v148 · JavaScript · Web Workers
Keepalive Timer
The core difference between standard and extended-lifetime shared workers: when all client tabs disconnect, the standard worker terminates immediately (timer resets). With extendedLifetime: true the worker keeps running for a grace period — the timer continues ticking. Simulate clients connecting and disconnecting to see the keepalive behaviour.
Checking SharedWorker support...
Standard vs extended-lifetime keepalive
Constructor probe has not run yet.
Standard SharedWorker
00:00
idle
Clients connected:
Extended-lifetime (Chrome 148)
00:00
idle
Clients connected:
Event log
Click "Connect client" on each side to start both workers, then click "Disconnect" repeatedly until zero clients remain. The standard worker stops immediately. The extended-lifetime worker keeps running for a grace period.
// Standard SharedWorker — terminates when all clients disconnect
const standard = new SharedWorker('worker.js');
// Chrome 148: extendedLifetime — survives zero-client periods
const extended = new SharedWorker('worker.js', {
extendedLifetime: true,
// Worker keeps running after last client disconnects
// Useful for: flushing write buffers, analytics pings,
// background sync before full termination
});
// Inside the extended-lifetime worker script:
self.addEventListener('connect', e => {
// Standard worker lifecycle event
});
// Worker also receives 'beforeunload' and 'unload' to do
// cleanup work before the grace period ends
see also
- Persistent Counter — counter that outlives tab closes
- Background Channel — persistent message queue
- Offline Queue — analytics queue that survives disconnects
- Worker Lifecycle Demo — full lifecycle state machine
references
implementation reference
Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗