demo · v139
Freeze Timeline
Background tabs on Android freeze sooner — within ~1 second of backgrounding, down from 5. Switch this page to a background tab to fire real visibilitychange + freeze events, or click "Simulate" to see the timeline rendered side-by-side.
Switch this page to another tab to fire a real visibilitychange event.
visible/active
backgrounded (still running)
frozen
pre-v139
v139
the code
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "hidden") {
// v139: you now have ~1s before freeze, not ~5s
flushLogs();
}
});
document.addEventListener("freeze", () => {
// last chance to persist state
saveCriticalState();
});
document.addEventListener("resume", () => {
rehydrate();
});