Chrome's unload Death: Page-Unload Reporting Methods That Survive
I Tested 5 Page-Unload Reporting Methods; Two Legacy Methods Sent Zero
Chrome 155 on October 16 completely disabled the unload event: it no longer triggers by default. But many tracking SDKs still assemble their last piece of data inside unload and send it via synchronous XHR—this pattern has been used for ten years.
On my local Chrome 158, I ran each of 5 page-unload reporting methods three times; two legacy methods delivered zero requests to the server.
Let me clarify what I tested: when the user closes the page or navigates away, does the page still get a chance to send data? The server logs every request; if it arrives, it's alive; if not, it's lost.
Five methods, three survive
| Method | Close page 2 times + navigate 1 time | Verdict |
|---|---|---|
| fetch (without keepalive) | 3/3 arrived | Arrives, but not guaranteed |
| fetch + keepalive | 3/3 arrived | Stable |
| navigator.sendBeacon | 3/3 arrived | Stable |
| Image GET (new Image) | 3/3 arrived | Only if payload is small |
| Synchronous XHR | 0/3 arrived | Dead |
The synchronous XHR issue isn't a coding mistake—the browser no longer allows it. On the same page, running synchronous XHR while the page is alive returns 204 normally; during the closing phase, none get out.
First cause: wrong timing
I first tested timing rather than methods—when the page is closing, which events actually fire?
Results: pagehide fires, visibilitychange fires, unload never fires. Chrome officially stated on October 16 that unload handlers are no longer executed by default.
So if your reporting looks like this:
window.addEventListener('unload', () => {
navigator.sendBeacon('/log', data);
});
The method is correct, sendBeacon is correct, but the outer wrapper will never execute. Many people debugging this check network, CORS, server—but not "did this code even run?"
One detail: beforeunload fires on same-site navigation but not on programmatic close. It's meant for the "you have unsaved changes" confirmation dialog, and shouldn't be used for reporting.
Second cause: synchronous XHR is banned during page unload
Synchronous XHR was once the standard answer for page-unload reporting—when the page is about to die, only it can guarantee the request goes out.
Since Chrome 80, synchronous XHR has been disabled during page unload: the era of blocking the main thread to save one piece of data is over. In my test, it returned 204 fine while alive, but during close and navigation it delivered 0.
Some SDKs still keep this code as a fallback, and don't log—if the request can't be sent, it fails silently, and data quietly disappears.
Under weak network, Image GET also dies
Image GET is an old fallback: new Image().src = url, no CORS concerns, no response needed. On a normal network it arrived 3/3, looking fine.
But I limited the network to 400ms latency, 32KB/s upload, and ran the same 5 methods for three more rounds; the results changed:
| Method (weak network, 8KB payload) | Three rounds | Description |
|---|---|---|
| fetch | 2/2, 2/2, 2/2 | All arrive |
| fetch + keepalive | 2/2, 2/2, 2/2 | All arrive |
| sendBeacon | 2/2, 2/2, 2/2 | All arrive |
| Image GET | 0/2, 0/2, 0/2 | All lost |
| Synchronous XHR | 0/2, 0/2, 0/2 | All lost |
Image GET is cancelled at the moment of page close; the request never actually goes out. Size isn't the problem—the URL has just a few parameters—the issue is that it has the lowest priority during page close, and the browser simply drops it.
So Image GET can only be a last resort for small payloads, and only when the network is good. As a primary path, weak-network users' data is effectively not collected.
64KB is a hard ceiling, and two requests share it
Both sendBeacon and fetch keepalive have a 64KB limit, but they fail differently, which many miss:
| Scenario | Result |
|---|---|
| sendBeacon 60KB | returns true, server receives |
| sendBeacon 70KB | returns false, silently doesn't send |
| fetch keepalive 60KB | Sending succeeds |
| fetch keepalive 70KB | Throws TypeError: Failed to fetch |
| Two keepalive requests each 40KB | The second throws TypeError |
The last row is the trap: 64KB is not per-request, it's shared among in-flight keepalive requests. If you send two 40KB requests at once, the second fails—if your tracking sends two modules at the same time, you'll hit this sooner or later.
fetch without keepalive has no such limit, but the spec allows the browser to terminate it during page unload. Over loopback on my machine it arrived, but don't rely on it in production on weak networks. For large payloads without loss, you have to chunk, or accumulate data before reporting.
Third pitfall: the same close sends data twice
This is a detail I noticed after testing. Closing a tab once triggers both pagehide and visibilitychange—each method I tested produced two records on the server.
If your code attaches reporting to both events, one leave results in double data. Every time a user closes a tab, your "page dwell time" statistic gets an extra count; if there's a funnel, the same person can be counted twice.
More insidious is tab switching: visibilitychange fires when you switch away, and the user might return half an hour later, with the page still alive. If you report "leave" at hidden and don't deduplicate, the same session gets split into multiple segments.
My deduplication is simple:
let sent = false;
function reportOnce(payload) {
if (sent) return;
sent = true;
report(payload);
}
Both events call reportOnce; the first to fire sends, the other skips. The cost is that if the user switches away and comes back, subsequent leaves won't be reported—so either reset sent when visibilitychange becomes visible, or use pagehide only for true closes.
No arrangement satisfies both "report on tab switch" and "report on close" without duplication—you have to choose based on business needs. That's why I recommend only visibilitychange: it covers both switching and closing, and semantically "page is not visible" is the event you want, not "page is about to be destroyed."
So how to write it
My conclusion in three sentences:
- Use
visibilitychange+hidden: covers both tab switch and close; addpagehidewithpersistedonly when you need to distinguish bfcache, but wrap it with the dedup above. - Default to sendBeacon, within 64KB, same-origin, non-blocking for close flow.
- For custom headers or large payloads, use fetch keepalive, and ensure total in-flight data at any moment is within 64KB.
A copy-paste wrapper:
function report(payload) {
const body = JSON.stringify(payload);
if (!navigator.sendBeacon('/log', body)) {
fetch('/log', {
method: 'POST',
body,
keepalive: true,
headers: { 'Content-Type': 'application/json' },
}).catch(() => {});
}
}
addEventListener('visibilitychange', () => {
if (document.visibilityState === 'hidden') {
report({ type: 'hide', at: Date.now() });
}
});
With only one event, there's no duplicate reporting. If you also add pagehide to detect bfcache, don't skip the persisted check—if it's true, the page entered the cache and the user may return at any time; reporting "leave" then is semantically wrong.
Spend three minutes checking your existing code
Search your project for three terms; that will locate the problem:
unload: any reporting code hit is already broken.XMLHttpRequestwith third argumentfalse: synchronous XHR, can't be sent during close.new Image()for tracking URLs: likely drops on weak networks.
Verification is easy: point the reporting URL at a local service, add logging, and manually close the tab. Arrival means alive, no arrival means lost. Don't trust "the code uses sendBeacon"—if the outer timing is wrong, what's inside is pointless.
Finally
This test used Chrome 158, loopback, and weak network simulated via DevTools. I didn't test Firefox or Safari; I won't speak for them.
But one thing doesn't need cross-browser verification: the two old paths, unload and synchronous XHR, are no longer viable in Chrome. Your tracking data isn't lost to network jitter; it's lost to a decade-old piece of code.
Which method do you use for page-close reporting? Ever encountered "data doesn't match but you can't find why"? Leave a comment; I'll pick a few typical cases to analyze in the next post.
Top 1 of 2 from juejin.cn, machine-translated. The original thread is authoritative.
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.