v148 · JavaScript · demo

Background Channel

Post messages into a worker, then disconnect. With extendedLifetime: true, the worker buffers and processes them while no clients are connected — reconnect to collect the results.

Checking support…
Extended-lifetime SharedWorker — persistent message queue

Client

Worker (simulated)

// Worker holds a queue even when no clients are connected
const workerCode = `
  const queue = [];
  let processing = false;

  self.onconnect = (e) => {
    const port = e.ports[0];
    // Flush queue to reconnecting client
    while (queue.length) port.postMessage(queue.shift());
    port.onmessage = (ev) => {
      queue.push({ result: process(ev.data), timestamp: Date.now() });
    };
    port.start();
  };
`;

// With extendedLifetime: true, the worker above survives
// after all ports close and continues receiving & queuing messages
const worker = new SharedWorker(workerURL, {
  extendedLifetime: true,  // Chrome 148+
});

see also

implementation reference

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