v160 · network · webtransport

WebTransport connection statistics

A WebTransport app that stutters needs to know whether the network is slow, the path is congested, or its own code is dropping datagrams. Chrome 160 ships WebTransport.prototype.getStats(): one asynchronous call that resolves a WebTransportConnectionStats snapshot of the underlying QUIC connection — smoothed, minimum and variation of round-trip time in milliseconds, an estimated send rate in bits per second (or null), and a datagrams dictionary counting incoming datagrams dropped or expired and outgoing datagrams expired or lost. The numbers stay readable after the session closes.

Availability. On by default in Chrome 160 (Blink runtime feature WebTransportStats, status: "stable"). On older Chrome enable chrome://flags/#enable-experimental-web-platform-features or launch with --enable-blink-features=WebTransportStats. Firefox 158 and Safari 26.4 also ship getStats(), with different member sets. Every concept below that needs a live connection lets you choose the server; experiments that only need the method itself run anywhere.

concepts

  1. One snapshot, every unit

    The canonical call. Probe for the method, open a real session, await getStats(), and read each member decoded with its unit next to the raw JSON. Take a second snapshot to see it is a copy, not a live view, and a third after close().

  2. Member inventory: what the spec defines vs what you get

    An inspection tool. All eighteen spec members in one table — IDL type, unit, whether each is a "pooled connection stat", whether Chromium's IDL declares it — and a real result checked member-by-member with in. Toggle allowPooling to see the pooled-connection privacy rule.

  3. Adaptive bitrate monitor

    The product use case: poll getStats() on an interval, chart smoothedRtt against minRtt and estimatedSendRate, push real bytes through a stream, and pick a video tier from the estimate — holding steady with a stated reason when the estimate is null.

  4. Datagram loss lab: which knob dropped my datagrams?

    Set incomingHighWaterMark, incomingMaxAge and outgoingMaxAge, fire a burst of real datagrams at an echo server, and read which of the four stats.datagrams counters moved — your queue, your max-age, or the network.

  5. Lifecycle edges: connecting, failed, closed

    The method steps' branches, run for real: a call while connecting waits, a call on a failed session rejects with InvalidStateError, a call with the wrong this returns a TypeError-rejected promise, and stats survive close(). The first three need no server.

why it shipped

WebTransport moves real-time media, game state and telemetry over QUIC, and those apps adapt: lower the bitrate, send fewer datagrams, shorten deadlines. Until now they had to infer network health from their own timing, which mixes network delay with event-loop and application delay. QUIC already measures RTT, runs a congestion controller and counts losses; getStats() exposes a snapshot of that so the app can separate "the network is slow" from "my code is slow" and "the network lost my datagrams" from "I did not read them in time".

It is deliberately a snapshot, not an event stream: one promise per call, no change in how data is sent, no new connection. The spec lets a user agent leave out any member it does not support, and on a pooled connection it must leave out every member not marked as a pooled connection stat, so a session cannot learn the traffic volume of other sessions sharing its connection. Chromium currently exposes RTT, the send-rate estimate and the datagram counters, but not the byte and packet totals or atSendCapacity.

the API

const transport = new WebTransport("https://example.com:4433/live");
await transport.ready;

const stats = await transport.getStats();
// Chromium 160 shape (members absent until measured):
// {
//   smoothedRtt: 8.33,          // ms  (RFC 9002 §5.3)
//   rttVariation: 12.485,       // ms
//   minRtt: 0.117,              // ms  (RFC 9002 §5.2)
//   estimatedSendRate: 42625692,// bits/s, or null when there is no estimate
//   datagrams: { droppedIncoming: 32, expiredOutgoing: 0, lostOutgoing: 0 }
// }

// State rules (spec method steps):
//   "connecting" → the promise waits for the state to change
//   "failed"     → rejects with InvalidStateError
//   "closed"     → resolves with the most recent stats available

run your own echo server (for the live concepts)

This showcase has no HTTP/3 server of its own, and many networks block QUIC to public servers. A local echo server takes a few lines of Deno (2.x, unstable QUIC API) plus a short-lived ECDSA certificate that Chrome accepts through serverCertificateHashes. This is the exact setup the concept pages were verified against.

# 1. A ≤14-day ECDSA P-256 cert, and its SHA-256 hash in base64
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 \
  -keyout key.pem -out cert.pem -days 10 -nodes -subj "/CN=localhost" \
  -addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
openssl x509 -in cert.pem -outform der | openssl dgst -sha256 -binary | base64

# 2. wt-echo.ts — echoes datagrams and bidirectional streams
// A dropped client must not take the server down with it:
addEventListener("unhandledrejection", (e) => e.preventDefault());
const cert = Deno.readTextFileSync("cert.pem"), key = Deno.readTextFileSync("key.pem");
const listener = new Deno.QuicEndpoint({ hostname: "127.0.0.1", port: 4499 })
  .listen({ cert, key, alpnProtocols: ["h3"] });
for await (const incoming of listener) {
  (async () => {
    const wt = await Deno.upgradeWebTransport(await incoming.accept());
    await wt.ready;
    const r = wt.datagrams.readable.getReader(), w = wt.datagrams.writable.getWriter();
    (async () => { for (;;) { const { value, done } = await r.read(); if (done) break; await w.write(value); } })().catch(() => {});
    for await (const bs of wt.incomingBidirectionalStreams) bs.readable.pipeTo(bs.writable).catch(() => {});
  })().catch(() => {});
}

# 3. run it, then paste https://127.0.0.1:4499/ and the hash into a concept page
deno run --unstable-net --allow-net --allow-read wt-echo.ts

The endpoint fields remember your values for the browser tab, and accept ?url=…&hash=… in the page address.

references