v148 · workers · shipped

Persistence Across Reload

A SharedWorker keeps running between page reloads as long as at least one client is still connected. This demo shows a counter in the worker surviving page reloads — the key SharedWorker use case that's now available on Android Chrome 148+.

How it works: The counter lives inside the SharedWorker — not in localStorage or sessionStorage. When you click "Simulate reload", this page disconnects from the worker, reconnects, and reads the same counter back. On Android Chrome 148+, the worker survives the disconnect the same way it does on desktop.
Checking SharedWorker support...
Real SharedWorker probe has not run yet.
SharedWorker state Connecting…
Page loads
1
Worker counter
Increments
0
Companion client
on
Connecting to SharedWorker…
Event timeline:

why this matters on Android

Before Chrome 148 on Android, SharedWorker was disabled. Any state shared across tabs had to use localStorage, BroadcastChannel, or a server roundtrip. Chrome 148 enables SharedWorker on Android, so the same "counter in the worker" pattern that already works on desktop now works on mobile — one worker process, persistent state, no server needed.

// Feature-detect SharedWorker on Android Chrome 148+
if ('SharedWorker' in window) {
  const worker = new SharedWorker('/counter-worker.js');
  worker.port.onmessage = ({ data }) => {
    document.getElementById('count').textContent = data.count;
  };
  // Counter survives tab reloads as long as one tab is open
} else {
  // Fallback: BroadcastChannel + localStorage
}

references

implementation reference

Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗