Chrome's unload Death: Page-Unload Reporting Methods That Survive
Analytics and tracking SDKs that still rely on unload or synchronous XHR are silently losing all page-close data on Chrome, with no error surfaced. Switching to visibilitychange plus sendBeacon is the only way to keep that data flowing; the shared 64KB keepalive budget also needs a hard cap to avoid dropped requests.
Chrome 155, released October 16, disables the unload event by default, and synchronous XHR has been banned during page unload since Chrome 80. On a local Chrome 158 instance, running each of five page-close reporting patterns three times, only three delivered: fetch with keepalive, navigator.sendBeacon, and fetch without keepalive (though the last is not guaranteed). Unload handlers never fire, and synchronous XHR returns 0/3; both old patterns silently drop analytics data.
Under a simulated weak network (400ms latency, 32KB/s upload), image GET (`new Image().src`) also fails completely, because the browser cancels the request at close time due to low priority. sendBeacon and fetch keepalive both share a 64KB budget per page unload: two 40KB keepalive requests in flight cause the second to throw a TypeError. The article also highlights duplicate reporting: both pagehide and visibilitychange fire on tab close, so attaching to both without a sentinel flag records every leave twice.
The recommended pattern is to listen only to visibilitychange and check visibilityState === 'hidden', then send via sendBeacon, falling back to fetch keepalive for payloads over 64KB or custom headers. A dedup flag prevents double sends. Developers should search their codebases for unload, synchronous XHR, and new Image() tracking URLs, and verify with a local server.
The browser's lifecycle model now punishes legacy assumptions: unload is gone, sync XHR is blocked, and image GET is deprioritized. Only sendBeacon and keepalive are designed for the modern lifecycle.
The shared 64KB budget is a hidden constraint: many SDKs send multiple payloads per unload, so they hit the second-request failure even when each payload is well under the limit.
Dual-event firing means any robust implementation must treat reporting as a state machine, not a one-shot call. The visibilitychange-only approach trades bfcache detection for simplicity, a reasonable engineering trade for most analytics.
Add two edge cases beyond actual testing. First, sendBeacon returning true only means the browser accepted the payload, not that it reached the server - 70KB returning false is explicit, but when the network layer drops it, it still returns true, so deduplication cannot rely solely on the client's reportOnce; it's better to include a client-generated event_id (stored in sessionStorage, so it still hits after bfcache restore), and the server builds a unique index on event_id as a backstop. Second, visibilitychange also triggers once on bfcache restore; if sent is not reset, the leave after returning from back/forward cache will never be reported; the cost of resetting is to use id for deduplication instead of a boolean flag, and these two points are related.
A flash of inspiration.