demo · v140

Blob SharedWorker controller probe

Constructs a SharedWorker from a runtime Blob, then asks the worker to fetch a resource. If a service worker controls this page, v140 ensures the worker inherits that controller — so the fetch hits the SW handler. Otherwise it goes straight to the network.

log:

(idle)

// v140: the SharedWorker spawned from a blob: URL inherits
// the controlling service worker of the creating context.
const code = `onconnect = (e) => {
  const port = e.ports[0];
  port.onmessage = async (m) => {
    const r = await fetch(m.data);
    port.postMessage({ status: r.status, fromSW: r.headers.get("x-from-sw") });
  };
};`;
const url = URL.createObjectURL(new Blob([code]));
new SharedWorker(url);

see also