Open two copies of a 90-second countdown. Leave one in front and put the other behind a different tab. When you come back, both displays should describe the same moment. If the hidden one still has ten extra seconds on the clock, look at what the app is counting.
A timer that subtracts one every time an interval runs assumes the browser calls it once per second. Background tabs can have their timers throttled. The delay is ordinary browser behaviour, and changing the interval from one second to half a second leaves the assumption in place. The Page Visibility API documentation explains the visibility event and why browsers limit work in background tabs.
Save the end time when the user starts
For a local preview or practice timer, calculate the deadline once in the start handler. Render seconds remaining from that deadline. The interval just asks the display to check again.
const deadline = Date.now() + 90_000;
const secondsLeft = () =>
Math.max(0, Math.ceil((deadline - Date.now()) / 1000));
In a React component, keep the deadline in state, update the display from a function inside an effect and call that function immediately when the effect starts. Register it for the interval and for visibilitychange. In the effect’s cleanup, clear the interval and remove the listener. The React effect reference shows the same setup and cleanup pairing for external subscriptions.
Make the hidden tab part of the test
Start the timer and note the real finish time. Spend about 30 seconds elsewhere, then return. Check that the displayed time closes the gap on return. Hide it again until after the deadline, then confirm that the display stops at zero. Finally, start over to check that the old effect cannot update the new run.
A local display uses the device’s clock. If an offer, submission window or session really expires, have the service decide which requests still count. A smooth countdown is a useful explanation for the person holding the mouse. The service rule is what settles a late request.
