Skip to content

Extended lifetime shared workers (SharedWorkerOptions.extendedLifetime) #1382

Open

Description

@nickchomey

Description

With SharedWorker support being added to Chromium for Android 148, SharedWorkers have become a viable option for instantiating costly resources once per origin. Examples include WASM modules, SSE/WebSocket connections, in-memory search indexes, etc...

A challenge, however, is that SharedWorkers' lifetime is often shorter than expected.

Chromium 148 added a new extendedLifetime: true option for the SharedWorker constructor that keeps the worker alive briefly after its last client unloads, so pages can finish async work on unload (e.g. IndexedDB writes, encrypt/compress-then-fetch) without needing a service worker.

Another significant use-case that was not discussed much previously is when only one tab is open for the origin, thus the SharedWorker unloads and reloads every time you make any full-page navigation - which can be very unnecessarily costly depending on what the SharedWorker is doing. This is particularly prevalent in a PWA context, which realistically only ever has a single tab open. So, if the PWA is an MPA, every navigation re-instantiates the SharedWorker. In that sense, extendedLifetime reduces the need for more complicated SPA architectures.

const worker = new SharedWorker("worker.js", { extendedLifetime: true });

The lifetime is capped at the existing service-worker no-client lifetime — no new background-execution capability, just parity with service workers. See theexplainer and origin trial write-up for background.

A spec has already been written for this, so it would be fantastic if support could be made universal.

Relevant discussions:

Specification

web-feature

shared-workers

Note for the triage bot: api.SharedWorker.SharedWorker.options_extendedLifetime_parameter is in BCD but is not currently listed in the shared-workers web-feature's compat_features, so the auto-generated status summary may not reflect this sub-feature.

Test Links

Promoted out of tentative/ in April 2026; all run in Chrome, Edge, Firefox and Safari desktop runs. Aggregate: https://wpt.fyi/results/workers?q=extendedLifetime

Current results (master @ 92054a74d0, 2026-09-08):

Test Chrome 155 Edge 154 Firefox 157 Safari 251 preview
SharedWorker-extendedLifetime.html pass pass fail fail
...-blob.html pass pass pass pass
...-data.html pass pass pass pass
...-named-module.html 2/2 2/2 0/2 0/2
shared-worker-options-mismatch.html 32/32 32/32 24/32 24/32

The 8 mismatch failures in Firefox and Safari are exactly the new extendedLifetime mismatch subtests, which is consistent with the option not being implemented (an unrecognised dictionary member is silently ignored rather than causing a mismatch error). I would flag that the current coverage is thin and mostly a single behavioural scenario; I expect the focus area to need additional tests, for example around name/URL identity, reconnection to a worker with zero clients, close(), and the bfcache cases that #11520 leaves open.

Additional Signals

Standards positions:

Current state:

Browser bugs:

Workaround:

  • sites register a service worker purely to run async code after unload (persistent registration, disk, resident process, separate same-origin script). See explainer and OT write-up.

Developer demand:

  • first-hand reports in whatwg/html#10997 (e.g. shared WebSocket across navigations, wasm re-init costs); 35 origins in the Chrome OT.

Compatibility impact: not polyfillable — without the option the worker is killed and the data is lost.

Platform impact:

  • lifetime capped at the service-worker no-client lifetime, so no new background-execution capability
  • replaces a persistent SW registration with a short-lived worker. See the explainer's security/privacy self-review.

Activity

  1. github-actions commented on Sep 8, 2026

    @github-actions

    This comment was automatically generated based on the information you provided. Please don't edit it.

    Below is additional information about the web feature (from the web-features project) which is referenced in your proposal.
    If this doesn't accurately correspond to your proposal, please update your initial comment to include web-features: <feature-id>.
    To find feature IDs, use the web-features explorer.

    Feature Shared worker extended lifetime

    • ID: shared-workers-extended-lifetime
    • Name: Shared worker extended lifetime
    • Description: The extendedLifetime option of the SharedWorker() constructor gives shared workers extra time to perform operations after all pages using it have been navigated away from or closed.
    • Baseline status: Limited Availability
    • Developer signals: 1 votes (details)
    • More information: See the web-features explorer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    focus-area-proposal

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions