Background Tab Throttling
Browsers deliberately slow, freeze, or discard pages that are not visible, so code that assumes it keeps running in the background will be wrong.
Background tab throttling is the set of measures browsers take to stop invisible pages from using CPU and battery. A page in a hidden tab, a minimized window, or sometimes just a covered window does not get the same treatment as the one being looked at. Each step is more aggressive than the last:
- Rendering stops. requestAnimationFrame callbacks pause, so animations and anything waiting on a frame stall.
- Timers are clamped.
setTimeoutandsetIntervalfire at most about once a second. - Intensive throttling. After several minutes hidden, chained timers can be held to roughly once a minute.
- Freezing. The page's task queues stop entirely. Nothing runs until the tab is shown again.
- Discarding. Under memory pressure the tab is unloaded altogether and reloaded from its URL when revisited, with all in-memory state gone.
Exemptions exist (a page playing audio, an active WebRTC call), and the exact thresholds differ between browsers and versions. The safe assumption is that a hidden page may get no CPU at all.
The bugs this causes follow a pattern: code that measures time by counting ticks, polling loops that silently stop, heartbeats that lapse so the server decides the client is gone, and a WebSocket that dropped while the page was frozen and never reconnects. They show up as heisenbugs: never during development, where the tab is always in front, and constantly for users who leave tabs open all day.
The robust patterns treat visibility as an event to handle rather than a condition to wish away:
- Listen to
visibilitychange(and the Page Lifecyclefreeze/resumeevents). Pause work when the page is hidden, then on return re-sync from the source of truth rather than assuming nothing changed. - Compute from wall-clock time, never from callback counts.
- Persist state that matters before the page can be frozen or discarded.
pagehideis the last reliable moment;unloadis not. - Move true background work elsewhere: a Service Worker for push and sync, or the server for anything that must finish regardless. A long-running job shouldn't depend on a tab staying open.
Cross-Tab Communication has the same issue: a message posted to a frozen tab is not processed until it wakes, so the receiver has to tolerate arriving late.
See also8
Tabs
A row of labels that switch between panels of content occupying the same space, borrowed from paper folder tabs, suited to parallel sections viewed one at a time, and governed by a specific keyboard pattern.
Design & Interface12 connections
Event Loop
A single-threaded runtime's mechanism for pulling the next callback off a queue once the call stack is empty.
Computation & Algorithms19 connections
Web Worker
A background thread for running JavaScript off the main thread, with no access to the DOM.
Web Platform12 connections
WebSocket
A persistent, full-duplex connection between browser and server, replacing repeated request-response with an open channel.
Web Platform16 connections
Silent Failure
A failure that produces no signal, so the absence of an error reads as success.
Method73 connections
Progressive Web App
A website that can be installed like a native app, launched from the home screen in its own window and used offline, built from a manifest, a service worker and HTTPS.
Web Platform9 connections
Back-Forward Cache
Browsers keeping a whole page frozen in memory when you navigate away, so pressing Back restores it instantly, unless something on the page makes it ineligible.
Web Platform10 connections
Long Polling
The ways a client learns that something changed on a server, from asking repeatedly, to holding a request open until there's news, to the push channels that replaced both.
Networks & Distribution11 connections
Linked from8
- Back-Forward CacheWeb Platform
Browsers keeping a whole page frozen in memory when you navigate away, so pressing Back restores it instantly, unless something on the page makes it ineligible.
- CompositorGraphics & Rendering
The component that draws each window or layer into its own off-screen buffer and then combines them into the final image, which makes transparency, effects, and tear-free output possible at a small latency cost.
- Cross-Tab CommunicationWeb Platform
Keeping several open tabs of the same app consistent, best done by broadcasting small notifications and letting each tab re-read the truth.
- Event LoopComputation & Algorithms
A single-threaded runtime's mechanism for pulling the next callback off a queue once the call stack is empty.
- Long PollingNetworks & Distribution
The ways a client learns that something changed on a server, from asking repeatedly, to holding a request open until there's news, to the push channels that replaced both.
- Progressive Web AppWeb Platform
A website that can be installed like a native app, launched from the home screen in its own window and used offline, built from a manifest, a service worker and HTTPS.
- requestAnimationFrameWeb Platform
The browser callback that runs once per display frame just before paint, which is the right clock for visual work and stops entirely when nothing is being displayed.
- TabsDesign & Interface
A row of labels that switch between panels of content occupying the same space, borrowed from paper folder tabs, suited to parallel sections viewed one at a time, and governed by a specific keyboard pattern.