Browser troubleshooting
Why timers slow down in background tabs
Browsers can throttle timers and other work when a tab is hidden. A delayed interval does not necessarily mean a script has stopped or the server has failed.
Worked example
Browser console example · use a disposable page on your own site
console.log(document.visibilityState);
function reportVisibility() { console.log(document.visibilityState); }
document.addEventListener("visibilitychange", reportVisibility);
// After observing a tab switch, clean up this demo listener:
// document.removeEventListener("visibilitychange", reportVisibility);How it works
Visibility state lets an application observe when its document becomes hidden or visible. Use elapsed timestamps for timing-dependent displays rather than counting interval callbacks as if every tick occurred on schedule. Pause nonessential visual work while it cannot be seen.
Limits and mistakes
The exact throttling policy varies with browser and conditions. Visibility is not proof that a person is paying attention, and a visible page may still face scheduling delays. Important server-side deadlines should not depend on a browser tab’s timer cadence.
Check the result
Switch to another tab and return while observing the state changes. Check that the application recomputes elapsed time from a clock source rather than accumulating one assumed second per callback.
Sources
Reference documentation for the behavior used in this guide: