Skip to content

Glossary

What is sendBeacon?

sendBeacon is a browser API for sending a small request that survives the page closing. Session replay SDKs use it to flush the last events of a session.

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.

Start free — 1 project, 500 sessions a month

Install the snippet, record a session, and watch it back in your own language.