demo · v140

Cross-tab WebSocket

The chromestatus motivation: one WebSocket connection shared across multiple tabs of the same origin — saving battery, server load, and message dedupe. SharedWorker has worked on desktop forever. Chrome 140 re-enables it on Android. This demo runs three simulated tabs sharing a single SharedWorker channel.

tab 1

tab 2

tab 3

SharedWorker support: checking…
// shared-worker.js — runs once, lives across tabs
let socket = null;
const ports = new Set();

onconnect = (e) => {
  const port = e.ports[0];
  ports.add(port);
  if (!socket) {
    socket = new WebSocket("wss://hub.example/feed");
    socket.onmessage = (m) => ports.forEach(p => p.postMessage(m.data));
  }
  port.onmessage = (m) => socket.send(m.data); // outbound multiplexing
};

// tab.js (any tab, any platform — including Android since Chrome 140)
const w = new SharedWorker("/shared-worker.js");
w.port.start();
w.port.onmessage = (m) => render(m.data);
w.port.postMessage(JSON.stringify({ kind: "subscribe" }));

see also