Skip to tool
ecech.
🕑 Date, Time & Timezone

A Timer That Is Still Right After an Hour in a Background Tab

Counting setInterval ticks loses time on every late fire. This reads the clock instead, so it stays accurate even when the tab is throttled.

00:00.00

space to start and stop · L for a lap · R to reset
Advertisement

How the calculation works

One hour later, in a background tab counting ticks count += 1000 every interval every late or skipped fire is lost reads 51:12 reading the clock elapsed = now − start a missed frame changes nothing reads 60:00 The display can stutter. The number cannot be wrong, because it is not being counted.

How to Use This Tool

Switch between the stopwatch and the countdown at the top. Both keep time from the system clock rather than by counting intervals, which is what makes them survive a background tab.

Why most web timers drift

The natural way to build a timer is to run setInterval every second and add one to a counter. It is wrong, and the reason is in the specification: setInterval guarantees the callback fires no sooner than the delay, not that it fires on time.

When the browser is busy, a garbage collection runs, or another tab takes the main thread, the callback is late. A counter-based timer never learns about that lateness — each tick still adds exactly one second — so the error accumulates and only ever goes one way. Over an hour it is typically several seconds short.

Recording the start time and computing now − start on each frame removes the whole problem. The display might stutter if the browser is busy; the number cannot be wrong, because it is being read rather than counted.

Background tabs make it much worse

Browsers deliberately throttle timers in hidden tabs to save battery — typically to once per second, and after a few minutes to once a minute or less. Mobile browsers may suspend a background tab entirely.

A counter-based timer loses everything that happened while it was throttled. A timestamp-based one shows the correct time the instant you switch back, because it never needed the ticks in the first place.

What happens to timers in a hidden tab visible tab up to 60 times a second hidden tab throttled to about once a second hidden for minutes once a minute, or suspended on mobile None of this matters if you read the clock instead of counting.
The throttling is intentional and not something a page can opt out of.

The alarm has a limitation worth knowing

Sound is played through the Web Audio API, which requires a user interaction before it will make any noise — pressing start counts. If you load the page and immediately expect an alarm without touching anything, browsers will block it, and that is a deliberate protection against pages that autoplay audio.

A suspended mobile tab may also not run the code that triggers the alarm at all until you return. For anything that genuinely must wake you, a phone's own alarm is the right tool; a browser tab is not designed for it and the platforms actively prevent it.

Laps and splits

The stopwatch records both, and they answer different questions:

  • Lap — the time for that segment alone.
  • Split — the total elapsed at that point.

For intervals or repeats you want the lap column; for tracking progress against a target you want the split. The fastest and slowest laps are marked, because that is usually the thing you are looking for.

Advertisement

Frequently Asked Questions

Why do online timers lose time?
Because most count setInterval ticks, and setInterval only guarantees the callback fires no sooner than the delay — never that it fires on time. Every late fire is permanently lost from a counter, so the error accumulates in one direction, typically several seconds over an hour.
Does a timer keep running when I switch tabs?
The page's timer callbacks are throttled — to about once a second in a hidden tab, and less after a few minutes — and a mobile browser may suspend the tab entirely. A timer that reads the system clock is unaffected and shows the correct time the moment you return; one that counts ticks comes back behind.
Will the alarm sound if the tab is in the background?
Usually, on desktop. On mobile a suspended tab may not run the code at all until you return to it. Browsers also require a user interaction before any audio can play, which pressing start satisfies. For anything you genuinely must be woken by, use a phone alarm.
What is the difference between a lap and a split?
A lap is the time for that segment alone; a split is the total elapsed when you pressed the button. Laps are what you want for intervals and repeats, splits for tracking progress against a target time.
How accurate is a browser timer?
The measurement is as accurate as the system clock, which is far better than anything you need for a stopwatch. The display refresh is what stutters when the browser is busy, and that does not affect the recorded number since it is computed rather than accumulated.
Can I close the tab and keep the timer running?
No. Closing the tab ends the page and everything in it. A timer that must outlive the tab needs a notification scheduled by the operating system, which a web page cannot do without permission and a service worker — and even then not reliably on mobile.

Related tools in Date, Time & Timezone

Browse all Date, Time & Timezone tools
A handwritten note reading ecech.com resting on the keyboard used to build the site.

Made by one person

ecech. is not a content farm. Every tool here is written and checked by hand, one at a time, by someone who wanted the tool to exist and could not find a version that showed its working.

No accounts and no sign-in, and nothing you type reaches a server — every calculation on this page runs inside your browser. The ads are served by Google and do set their own cookies, which is set out in full on the privacy page. More about the site.