demo · v140
Multi-tab Bus
Open this page in two tabs (or two windows on Android Chrome 140+). Both connect to the same SharedWorker; a message from one is rebroadcast to the other. The pattern that's been desktop-only since Chrome 8.
SharedWorker not available
Try Chrome 140+ on Android, or any current desktop Chromium.
disconnected
tab id
open this page in another tab to see messages echo
// inline blob to keep the demo self-contained
const code = `
const ports = new Set();
onconnect = (e) => {
const p = e.ports[0]; ports.add(p);
p.onmessage = (m) => {
for (const o of ports) if (o !== p) o.postMessage(m.data);
};
p.start();
};
`;
const url = URL.createObjectURL(new Blob([code], { type: "text/javascript" }));
const w = new SharedWorker(url, { name: "tab-bus" });
w.port.onmessage = (m) => render(m.data);
w.port.start();
w.port.postMessage("hello from this tab");
see also
- SharedWorker on Android — feature index
- SharedWorker spec