v159 · webtransport · migration

Migration shim

Your code will run on Chrome builds before and after 159 for a long while. The two halves of this change are independent — the constructor overload has no flag, while serialization has its own writer-side runtime switch — so detect each one separately, never from the browser version. This page runs the probes, then a small constructor shim and clone helper that use the native path when it exists and say exactly what they lost when it does not.

Everything below is live. On Chrome 159 all three probes should pass and the shim takes the native path. In a developer-trial build turn on chrome://flags/#enable-experimental-web-platform-features; if only serialization is off, relaunch with --enable-blink-features=WebTransportErrorSerialization. On older builds the shim falls back to the legacy dictionary constructor and a plain-record clone, and reports each downgrade.

1 · Three independent probes

Each probe calls the exact surface it names and can return false. None looks at navigator.userAgent.

2 · A constructor shim that admits what it dropped

function createWebTransportError(message = "", { source = "stream", streamErrorCode = null } = {}) {
  try {
    return { error: new WebTransportError(message, { source, streamErrorCode }), native: true, downgrades: [] };
  } catch (e) {
    if (e.name !== "TypeError") throw e;          // e.g. an invalid source is a real bug
    const downgrades = [];
    const init = { message };
    if (streamErrorCode !== null) init.streamErrorCode = streamErrorCode;
    const error = new WebTransportError(init);    // legacy: [Clamp] octet, no source
    if (source !== error.source) downgrades.push(`source "${source}" became "${error.source}"`);
    if (streamErrorCode !== error.streamErrorCode) downgrades.push(`streamErrorCode ${streamErrorCode} became ${error.streamErrorCode}`);
    return { error, native: false, downgrades };
  }
}

Not run yet.

3 · A clone helper with an honest fallback

function toCloneable(error) {
  try { structuredClone(error); return error; }    // native [Serializable]
  catch (e) {
    if (e.name !== "DataCloneError") throw e;
    return { __webTransportError: true, message: error.message,
             source: error.source, streamErrorCode: error.streamErrorCode };
  }
}
function fromCloned(value) {                        // receiving side
  return value?.__webTransportError ? value /* plain record, not a WebTransportError */ : value;
}

    Not run yet.

    4 · Edge: an error inside an error’s cause

    Applications often wrap transport failures: new Error("upload failed", { cause: wtError }). Cloning the wrapper clones its cause too, so a non-serializable WebTransportError can break the whole message. This clones the wrapper and reports what the cause became.

    Not run yet.

    see also