v139 · JavaScript · Web Workers
Extended lifetime shared workers
Pass extendedLifetime: true to the SharedWorker constructor and the worker continues running after all client pages close — enabling true background processing without a Service Worker.
concepts
-
Persistent Counter
A shared worker that ticks a counter every second. Simulate connecting and disconnecting all client pages — with a standard worker the counter resets; with
extendedLifetime: trueit keeps running. -
Background Channel
A worker used as a persistent message queue. Clients post messages, disconnect, then reconnect — the worker held onto the queue while no clients were connected and delivers on reconnect.
-
Cross-Tab State Bus
Open in two tabs. A shared worker mediates a tick counter and an event bus, broadcasting state to every connected tab and surviving zero-tab gaps. Local log of what you sent, broadcast log of what the worker said back.
-
Tab Presence Board
A real SharedWorker (blob URL) tracking connected tab IDs with a live count and per-tab list. Broadcast a message to all tabs, watch it appear in the message log. A worker uptime ticker shows the worker staying alive even after all tabs disconnect.
why it shipped
Shared Workers are great for cross-tab coordination — a single worker instance shared by all open tabs. But standard Shared Workers are terminated as soon as the last client tab closes. If you need the worker to finish an asynchronous operation (flushing a write buffer, completing an analytics ping, finishing a background sync) after the last tab navigates away, you previously had to reach for a Service Worker — a heavier primitive with its own lifecycle complexity. The new extendedLifetime: true option tells the browser to keep the shared worker alive even with zero connected clients, for a grace period long enough to complete in-flight work.