Glossary
What is sendBeacon? Requests that outlive a closing tab
navigator.sendBeacon() queues a small POST the browser finishes after the page unloads, so a session's last events survive. Its 64 KiB cap, and how SDKs use it.
Updated · 1 min read
sendBeacon is a browser API (`navigator.sendBeacon`) that queues a small, fire-and-forget HTTP request which the browser completes even after the page that sent it has been closed or navigated away from.
Why it matters
The most interesting moment in a session is often the last one: the click that navigated away, the error just before the user gave up. A normal fetch started during page unload can be cancelled by the browser, so the tail of the recording silently disappears.
sendBeacon, and the equivalent fetch option keepalive: true, exist for exactly this. They hand the request to the browser and let the page die. The cost is a size limit: the Fetch standard caps in-flight keepalive bodies at 64 KiB.
How AnyReplay handles it
The AnyReplay web SDK uses fetch with keepalive, or sendBeacon, for the tail-of-session flush. Because headers count against the 64 KiB cap, the SDK keeps keepalive payloads under 56 KB. Regular chunks go out through the normal chunked upload path every 200 events or 5 seconds, so the beacon only ever carries a few seconds of events. If the transport fails, the events stay buffered and are retried with backoff; see circuit breaker. Every chunk, beacon or not, still passes the origin allow-list at ingest.