demo · v140
SharedWorker probe + counter
Detect SharedWorker support on this device. If it's available, the demo spins one up and shares a counter across all tabs of this origin — open this URL in a second tab to watch the count tick in sync.
—
Worker event log:
(initialising)
const w = new SharedWorker(URL.createObjectURL(new Blob([`
let count = 0;
const ports = [];
onconnect = (e) => {
const port = e.ports[0];
ports.push(port);
port.onmessage = (m) => {
if (m.data === "inc") count++;
else if (m.data === "reset") count = 0;
ports.forEach(p => p.postMessage(count));
};
port.postMessage(count);
};
`])));
see also
- SharedWorker on Android — feature index
- ChromeStatus entry