demo ยท v135
Analytics that survives an unload
The original WICG pending-beacon design centred on this scenario: pages want to send a closing analytics ping reliably, but sendBeacon and fetch(keepalive) both leak the request the moment the user hits the back button. fetchLater() queues each event with a long activateAfter; if the user leaves first, the browser flushes the queue. Click any event below to queue a native request or send a real fallback request to the backend receiver.
Behind a flag
fetchLater requires
chrome://flags/#fetch-later-api. Without it, this page sends the analytics event immediately with a real sendBeacon() or fetch({ keepalive: true }) fallback and labels it as fallback delivery.
fetchLater: ?
queued requests
activity log
the code
function logEvent(name, payload) {
const handle = fetchLater("/log", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ event: name, payload, ts: Date.now() }),
activateAfter: 60_000,
});
pending.add(handle);
}
see also
- fetchLater API — feature index
- Queue a deferred request — raw API form
- ChromeStatus entry
- WICG pending-beacon — motivation