Bug 194897 - navigator.sendBeacon does not work on visibilitychange callback for document unload
Summary: navigator.sendBeacon does not work on visibilitychange callback for document ...
Status: RESOLVED DUPLICATE of bug 151234
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: Safari Technology Preview
Hardware: Mac macOS 10.14
: P2 Normal
Assignee: Nobody
Keywords: InRadar
Depends on:
Reported: 2019-02-21 06:22 PST by Bastien Caudan
Modified: 2022-07-05 14:11 PDT (History)
5 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Bastien Caudan 2019-02-21 06:22:40 PST
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.
Comment 1 Radar WebKit Bug Importer 2019-02-21 20:49:37 PST
Comment 2 Daniel 2019-06-21 14:08:29 PDT
The visibilitychange event don’t fire at all during unload. This is a duplicate of issue #116769.
Comment 3 sideshowbarker 2020-09-24 23:33:46 PDT
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).
Comment 4 Sam Sneddon [:gsnedders] 2022-07-05 14:11:51 PDT

*** This bug has been marked as a duplicate of bug 151234 ***