🔄 The keepalive Request That Got Silently Capped at 64KB
Setting keepalive: true on a fetch() call (the standard way to reliably send analytics or logging data as a page unloads) comes with a strict payload ceiling enforced by the browser – typically a combined 64KB across every pending keepalive request at once. Go over it and the browser doesn’t raise a clear, catchable error specific to the limit – the request is simply never sent, or fails with a generic network error that’s easy to swallow, so the one batch of events most worth keeping (the user’s longest, busiest session) is exactly the one most likely to silently vanish.
🔎 The Problem
window.addEventListener('pagehide', () => {
const payload = JSON.stringify(collectedEvents);
// collectedEvents can be large on a long, active session -
// easily well past 64KB combined with any other pending
// keepalive request still in flight.
fetch('/analytics/batch', {
method: 'POST',
keepalive: true,
body: payload,
});
// No .catch fires with a specific "payload too large" error -
// it's simply never sent, and the page is already gone by
// the time anyone could notice.
});
✅ Fix: Cap or Chunk the Payload Before It Ever Reaches keepalive
- Measure the serialized payload size client-side and truncate or chunk it to stay comfortably under the combined 64KB limit before setting keepalive: true, rather than discovering the ceiling in production.
- For anything that isn’t strictly tied to the page unloading, send it earlier with a normal (non-keepalive) fetch that has no size restriction, and reserve keepalive specifically for the small, final summary that must survive the page closing.
- Add an explicit application-level acknowledgment from the server for critical events, so a silently dropped batch is detectable (missing data on the backend) instead of invisible on both ends.
⚠️ Why This Is Easy to Miss
- Every test session with a handful of sample events stays safely under the limit, so the code passes every manual check – only a real user’s heaviest, most valuable session is big enough to trigger the drop.
- There’s no dedicated exception type for this – it either silently never sends or rejects with the same generic error fetch() uses for unrelated network failures, so logging the error tells you almost nothing about the actual cause.
A request marked keepalive is a promise the browser keeps only up to 64KB – past that, the promise quietly expires along with the page.

