Blog / Timers
Why countdown timers skip seconds in background tabs
How Long Until editorial · 2026-03-12
Browsers throttle timers in hidden tabs. Timestamp subtraction keeps remaining time honest when you return.
A countdown that subtracts one from a seconds variable looks fine while you watch it. Hide the tab, wait, and the number is often late. Chrome and other engines delay setInterval in the background to save battery.
The fix is not a faster interval. Store the finish time as an absolute timestamp. On every paint, remaining time is target - Date.now(). If the tab slept for forty seconds, the display jumps forty seconds. That jump is correct.
How Long Until uses that pattern on the countdown timer and the online timer. Pause still works: the leftover milliseconds are stored, then a new finish timestamp is created on resume.
If you build your own widget, also listen for visibilitychange. When the document is visible again, run one extra tick immediately so the first frame after return is not stale.
This is not a claim about atomic clocks. It is a claim about not trusting a decrementing integer in a throttled tab.