With the example from the beacon spec (https://w3c.github.io/beacon/): document.addEventListener('visibilitychange', function() { if (document.visibilityState === 'hidden') { navigator.sendBeacon('/collector', data); } }); From manual tests on hidden cases, navigator.sendBeacon is triggered correctly when: - the browser is minimized. - the document is not the active tab But navigator.sendBeacon is not triggered when: - the browser unload the document Other browsers that support the Beacon API allow these requests to be sent.
<rdar://problem/48301429>
The visibilitychange event don’t fire at all during unload. This is a duplicate of issue #116769.
See the https://volument.com/blog/sendbeacon-is-broken#comments comments discussion for some real-world pain points developers are hitting due to this. (So that not only do we need to make developers aware that they shouldn’t be trying to use unload/onunload with sendBeacon(), and that they instead need to visibilitychange — but *also* need to check pagehide (because we don’t yet have visibilitychange working interoperably for them across the web platform).
*** This bug has been marked as a duplicate of bug 151234 ***