v160 · dom · workers · edge cases + migration

Null-sentinel migration

The connect event never carried a payload, so why would code read e.data? Because a worker often shares one handler between connect and message, and Chrome-only code learned that “data is null” meant “this is the handshake”. Chrome 160 makes it "". Below, eight patterns run inside a real shared worker against the real connect event; next to each is what the same code does with null (Chrome ≤159) and with "" (Chrome 160, Firefox, Safari).

Checking for SharedWorker…

Run the patterns

Not run yet.
Handler patterns: this browser vs. both behaviours
PatternThis browser (real event)with null (≤159)with "" (160+)Changes in 160?
—————

“This browser” is computed inside the worker from the browser-fired event. The two reference columns apply the identical expression to the literal values null and "" in this page, so you can see the branch flip even on a browser that only has one of the behaviours.

migrate to this

// Robust on every engine and every Chrome version:
self.addEventListener("connect", (e) => {
  const port = e.ports[0];        // or e.source — both are the inside port
  port.onmessage = (m) => handle(m.data);
});

// If one handler must serve both event types, branch on the TYPE, not the data:
function onAny(e) {
  if (e.type === "connect") return adopt(e.ports[0]);
  handle(e.data);
}

// Avoid: e.data === null · e.data == null · e.data ?? fallback · typeof e.data === "object"

To test your worker against the legacy value on Chrome 160+, launch Chrome with --disable-blink-features=SharedWorkerConnectEventEmptyStringData (no chrome://flags entry exists; the feature is a stable-by-default kill switch).

see also