← Chrome 160 reference · All APIs

v160 · workers · enabled by default

SharedWorkerConnectEventEmptyStringData

Chrome 160 aligns the SharedWorkerGlobalScope connect event with the HTML Living Standard by initializing MessageEvent.data to the empty string ("") instead of null. Firefox and Safari already initialize connect event data to "", making the event payload interoperable across all three browser engines.

Baseline Newly available — data === "" interoperable across Chrome 160, Firefox 65+, and Safari 16+

  • Chrome · 160 (desktop, Android, WebView)
  • Edge · 160 (Chromium-based, mirrors Chrome)
  • Firefox · 65+ (stable passes WPT; SharedWorker since 29)
  • Safari · 16+ (stable passes WPT)

The parent shared-workers web-feature is Baseline Newly available since 2026-05-05 per webstatus.dev (Chrome 5 desktop / 148 Android, Edge 79, Firefox 29, Safari 16). Prior to Chrome 160, Chromium diverged from the HTML standard by setting connect event data to null; BCD api/SharedWorkerGlobalScope.json notes Firefox fixed the same divergence in Firefox 65 and does not yet record a Chrome 160 note (checked 2026-11-24).

at a glance

Shipped inChrome 160 (desktop, Android, Android WebView; iOS null) — filed under “Enabled by default” in the milestone=160 listing
Runtime flagSharedWorkerConnectEventEmptyStringData, status stable in Blink’s runtime_enabled_features.json5 (kill switch for crbug 583449815; no origin trial, no chrome://flags toggle)
SpecificationHTML Living Standard — Run a worker · SharedWorker() constructor · MessageEvent
Blink sourceSharedWorkerGlobalScope::Connect() in shared_worker_global_scope.cc
Intentblink-dev Intent to Ship
Tracking bugcrbug.com/583449815
Web platform testsworkers/constructors/SharedWorker/connect-event.html (test source · worker script)
ChromeStatus5142074717503488 — SharedWorkerConnectEventEmptyStringData (component Blink>Workers)

why it changed

Both the Run a worker algorithm (for the initial client that starts a SharedWorker) and the SharedWorker() constructor (for subsequent clients attaching to an existing worker) require the user agent to fire a MessageEvent named connect with its data attribute initialized to the empty string (""). Chromium previously constructed the event using a legacy internal overload of MessageEvent::Create() that left data uninitialized (serialized as null to JavaScript), failing WPT connect-event.html while Firefox and Safari passed.

Source: ChromeStatus motivation (5142074717503488); Blink shared_worker_global_scope.cc lines 193–221.

Syntax

No new interfaces or attributes are added. The change updates the initialized value of MessageEvent.data on connect events dispatched at SharedWorkerGlobalScope (replaces pre-160 null with ""):

[Global=(Worker,SharedWorker), Exposed=SharedWorker]
interface SharedWorkerGlobalScope : WorkerGlobalScope {
  [Replaceable] readonly attribute DOMString name;
  undefined close();
  attribute EventHandler onconnect;
};

[Exposed=(Window,Worker,AudioWorklet)]
interface MessageEvent : Event {
  readonly attribute any data;
  readonly attribute USVString origin;
  readonly attribute DOMString lastEventId;
  readonly attribute MessageEventSource? source;
  readonly attribute FrozenArray<MessagePort> ports;
};

“…fire an event named connect at worker global scope, using MessageEvent, with the data attribute initialized to the empty string, the ports attribute initialized to a new frozen array containing inside port, and the source attribute initialized to inside port.”

This reference covers three parts of the contract: MessageEvent.data initialization to "", the full SharedWorkerGlobalScope connect event dispatch contract (onconnect, ports, source), and migrating code that checked for null.

Source: HTML Living Standard — Run a worker (normative quote fetched 2026-11-24); Blink shared_worker_global_scope.idl; Blink message_event.idl.

MessageEvent.data on connect events — inputs and outputs

Inputs. A connect event is triggered whenever a browsing context calls new SharedWorker(scriptURL, options) on the same origin and matching worker name (creating a new worker or attaching to an already running one). The caller cannot pass a custom payload to connect; the browser constructs the MessageEvent internally.

Outputs. When Chrome 160 dispatches the connect event inside SharedWorkerGlobalScope::Connect(), Blink calls event->initMessageEvent("connect", false, false, g_empty_string, nullptr, String(), port, [port]). Script reading event.data observes:

Source: Blink SharedWorkerGlobalScope::Connect(); WPT connect-event.js.

SharedWorkerGlobalScope connect event fields & lifecycle

Inputs and outputs. Every connect event delivered to self.onconnect or self.addEventListener("connect", handler) is a trusted MessageEvent carrying the newly entangled client MessagePort:

Properties of a browser-dispatched connect MessageEvent in Chrome 160
PropertyChrome 160 valueChrome ≤ 159 valueNotes
event.type"connect""connect"Unchanged
event.data"" (empty string)nullChanged in Chrome 160 to match HTML spec, Firefox, and Safari
event.portsFrozen array [insidePort] (length 1)Frozen array [insidePort]Contains the worker-side entangled MessagePort
event.sourceinsidePort (same object as event.ports[0])insidePortStrict identity event.source === event.ports[0]
event.origin""""Unchanged (empty string)
event.lastEventId""""Unchanged (empty string)
event.bubbles / cancelablefalse / falsefalse / falseNon-bubbling, non-cancelable

Lifecycle and ordering. On first startup, the worker script executes to completion, then the initial connect event is queued and dispatched; subsequent new SharedWorker() calls from other tabs/windows queue additional connect events on the same SharedWorkerGlobalScope. Assign self.onconnect = ... or call self.addEventListener("connect", ...) synchronously during top-level evaluation so the initial connect event is not missed. Remember that assigning port.onmessage implicitly starts the port’s message queue, whereas using port.addEventListener("message", ...) requires calling port.start() explicitly.

Source: HTML Living Standard — Run a worker; HTML Living Standard — SharedWorker(); Blink shared_worker_global_scope.cc.

Migrating from pre-160 null checks

Inputs and outputs. Most shared workers never inspect event.data inside onconnect and instead read event.ports[0] or event.source directly. Code is affected only if it relies on Chromium’s non-standard pre-160 event.data === null behavior — for example:

To remain compatible across both Chrome ≤ 159 and spec-compliant engines (Chrome 160+, Firefox 65+, Safari 16+), identify client connections via event.ports[0] (or event.source) rather than event.data === null, and check event.data === "" || event.data === null if an explicit empty-payload assertion is required.

Source: ChromeStatus interop & compatibility notes (5142074717503488); HTML Living Standard.

Errors, edge cases, and synthetic events

This change introduces no new exceptions or error paths on SharedWorkerGlobalScope or onconnect. Note two edge cases:

Source: HTML Living Standard — MessageEventInit; WPT connect-event.html.

Context and exposure

SharedWorkerGlobalScope is exposed exclusively inside shared worker execution contexts ([Global=(Worker,SharedWorker), Exposed=SharedWorker]), instantiated from same-origin Window contexts via new SharedWorker(url, options). No permission prompt or user activation is required. Shared workers are same-origin isolated and partitioned by storage key; in Chrome, desktop has supported SharedWorker since Chrome 4 and Chrome for Android since Chrome 148.

Source: Blink shared_worker_global_scope.idl; BCD api/SharedWorkerGlobalScope.json.

Examples

Live example from the Chrome Platform Showcase (route HEAD-checked 200, 2026-11-24): inspects event.data, event.ports, and event.source on a live SharedWorker connect event. Sibling concept demos (all HEAD 200): connection hub, null sentinel migration, and synthetic connect fidelity.Source: chrome-platform-showcase

Spec-compliant onconnect handler in a shared worker

// shared-worker.js (runs in SharedWorkerGlobalScope)
const clients = new Set();

self.onconnect = (event) => {
  const [port] = event.ports; // equivalent to event.source
  if (!port) return;

  // In Chrome 160+, Firefox 65+, and Safari 16+:
  // event.data === "" (was null in Chrome <= 159)
  clients.add(port);

  port.onmessage = (msg) => {
    for (const client of clients) {
      client.postMessage(msg.data);
    }
  };

  port.postMessage({
    type: "connected",
    connectData: event.data,
    isEmptyString: event.data === "",
    portMatchesSource: event.source === port,
  });
};
Source: WPT connect-event.js; HTML Living Standard.

Replacing fragile event.data === null checks

// BEFORE (broke on Firefox/Safari and breaks on Chrome 160+):
self.addEventListener("connect", (event) => {
  if (event.data !== null) return; // WRONG: event.data is "" in Chrome 160+
  const label = event.data ?? "default-connect"; // yields "" in Chrome 160+
  handlePort(event.ports[0], label);
});

// AFTER (interoperable across Chrome <= 159, Chrome 160+, Firefox, and Safari):
self.addEventListener("connect", (event) => {
  const port = event.ports[0] ?? event.source;
  if (!port) return;
  const label = event.data || "default-connect"; // handles both "" and legacy null
  handlePort(port, label);
});
Source: ChromeStatus 5142074717503488; BCD api/SharedWorkerGlobalScope.json.

Browser compatibility

Browser support for SharedWorkerGlobalScope connect event initializing event.data to "" (empty string). Combines BCD api/SharedWorkerGlobalScope.json with ChromeStatus 5142074717503488 and WPT connect-event.html (checked 2026-11-24).
Browserdata === ""Base connect event (BCD)Notes
Chrome (desktop)1604Chrome 4–159 initialized event.data to null; Chrome 160 enables SharedWorkerConnectEventEmptyStringData by default
Chrome (Android, WebView)160148SharedWorker shipped on Android in 148; data === "" enabled by default in 160 per ChromeStatus API record
Edge160 (mirror)79Chromium-based; BCD mirrors Chrome
Firefox6529BCD note: Firefox 29–64 used null; Firefox 65+ initializes data to "" and passes WPT
Safari (macOS, iOS)1616Stable Safari passes WPT connect-event.html per ChromeStatus
Source: BCD api/SharedWorkerGlobalScope.json; ChromeStatus API record (5142074717503488); wpt.fyi connect-event.html; webstatus.dev shared-workers.

Security and privacy

Changing the initial value of connect event data from null to "" introduces no new cross-origin capability, permission surface, storage channel, or fingerprinting signal. The worker remains bound to the same-origin and storage-partitioning rules of SharedWorker, and the empty string carries no client or browser state. ChromeStatus records both Security and Privacy reviews as Not applicable for this specification-conformance fix.

Source: ChromeStatus security & privacy review status (5142074717503488); HTML Living Standard — Run a worker.

Specifications

see also