Page-Exit Flush Mechanism
How do you guarantee the final analytics/crash batch arrives when the user closes the tab?
Pros
- Browser schedules `sendBeacon` / `fetch({ keepalive: true })` asynchronously AFTER tab closes without delaying navigation!
- Avoids deprecated `unload` event that breaks Back/Forward Cache (`bfcache`).
Cons & Pitfalls
- `sendBeacon` payload limit ~64KB per call — solved cleanly by capping batch size.
Interview Rule of Thumb: Pick `visibilitychange` + `sendBeacon` / `keepalive` for every telemetry SDK.