I built a little browser timer as a side project, and the first bug report I gave myself was "the countdown is wrong when I come back to the tab." Classic.
Here's the thing: browsers ration timers on hidden pages to save battery. Chrome documents three stages ( source ):
Minimal throttling : page is visible, or made sound in the last 30s. Timers run roughly on time.
Throttling : page is hidden. Timers get checked about once per second.
Intensive throttling (Chrome 88+): hidden for 5+ minutes, silent for 30+ seconds, and the timer chain count is 5 or more. Now timers get checked once per minute .
Firefox has its own rules too. MDN notes a 1s minimum in inactive desktop tabs and up to 15 minutes on Firefox for Android ( MDN ).
So if your countdown does this:
let remaining = 25 * 60 ; setInterval (() => { remaining -= 1 ; // assumes exactly 1s passed. it didn't.…