v159 · networking · webtransport

WebTransportError API alignment and serialization

Chromium’s WebTransportError predates the spec it implements. It only accepted a dictionary (new WebTransportError({message, streamErrorCode})), squeezed the stream error code into 8 bits even though the attribute is an unsigned long, and threw DataCloneError the moment you tried to postMessage one out of a worker. Chrome 159 adds the standard new WebTransportError(message, {source, streamErrorCode}) constructor, carries the full 32-bit code, and makes the error structured-clonable — while keeping the old dictionary constructor working.

How to run it. Enabled by default from Chrome 159; Firefox and Safari already ship the standard shape. In a developer-trial build, turn on chrome://flags/#enable-experimental-web-platform-features. Serialization has its own writer-side runtime switch, WebTransportErrorSerialization (status “stable” in Chromium’s runtime_enabled_features.json5); if a build has it switched off, relaunch with --enable-blink-features=WebTransportErrorSerialization. The new constructor has no flag of its own. Everything here runs without a WebTransport server — the network errors come from a real session attempt against an address that is guaranteed to refuse it.

concepts

  1. Constructor overloads

    Build an error with the standard (message, options) shape or the legacy dictionary shape, read back name, code, source and streamErrorCode, then run a matrix of call shapes — strings, dictionaries, undefined, null, an invalid source — to see which overload WebIDL picks.

  2. Stream error code range

    An inspection tool for the code itself: type any number and compare what the standard [Clamp] unsigned long keeps with what the legacy [Clamp] octet keeps, then see the HTTP/3 error codepoint the spec maps that code to on the wire.

  3. Worker error relay

    The everyday reason serialization matters: networking lives in a Worker, the UI lives in the page. A real failed session inside a Worker rejects with a WebTransportError, and the Worker posts that error object straight to the page — or reports the DataCloneError that pre-159 builds throw.

  4. Persisted error log

    IndexedDB stores values by structured serialization, so a 159 build can keep real WebTransportError objects in a diagnostics log and read them back after a reload. See exactly which fields survive the trip — and that stack deliberately does not.

  5. Migration shim

    Code that must run on both sides of the change: two independent probes (constructor, serialization), a constructor helper that reports when it had to fall back to the 8-bit legacy path, and a clone helper that ships a plain record only when the browser cannot clone the error itself.

why it shipped

The interface in the WebTransport spec gained a (message, options) constructor so that a WebTransportError can be built like any other DOMException, with an explicit source ("stream" or "session"). Chromium kept its older dictionary-only constructor, so portable code that worked in Firefox and Safari threw TypeError in Chrome. The stream error code is an application protocol value carried in RESET_STREAM and STOP_SENDING; the protocol allows 32 bits, but Chromium narrowed outgoing codes to 8 bits. And because the spec marks the interface [Serializable], an error raised in a worker or stored in IndexedDB should keep its source and streamErrorCode — Chromium refused to clone it at all. All three gaps showed up in the Interop 2026 WebTransport proposal.

the API

// Standard constructor (Chrome 159, Firefox, Safari)
const err = new WebTransportError("peer reset", {
  source: "stream",          // or "session"; default "stream"
  streamErrorCode: 70000,    // [Clamp] unsigned long?, default null
});
err.name;            // "WebTransportError"
err.code;            // 0 — no legacy DOMException code
err.streamErrorCode; // 70000

// Legacy constructor — still accepted by Chromium for compatibility
new WebTransportError({ message: "peer reset", streamErrorCode: 300 });
//   → source "stream", streamErrorCode clamped to 255 ([Clamp] octet)

// Serialization: message, source and streamErrorCode survive
const copy = structuredClone(err);
copy instanceof WebTransportError; // true
worker.postMessage(err);           // no more DataCloneError
writer.abort(err);                 // sends the full 32-bit code in RESET_STREAM

references