v160 · webtransport · getStats() · practical
Adaptive bitrate monitor
The use case the explainer names: a live-media or game client that adapts what it sends to what the network can carry. getStats() is a snapshot, not a stream, so the app polls it. This monitor samples on an interval you choose, plots smoothedRtt against minRtt (the gap is queueing delay) and estimatedSendRate, and picks a video quality tier from the estimate — holding steady, with a stated reason, whenever the estimate is null. Push real bytes through the session to see the estimate move.
Availability. Chrome 160 ships WebTransport.prototype.getStats() enabled by default — the Blink runtime feature WebTransportStats is status: "stable" in runtime_enabled_features.json5. On an older Chrome the method is absent: enable chrome://flags/#enable-experimental-web-platform-features and relaunch, or launch with --enable-blink-features=WebTransportStats (both verified on Chrome 153). Real numbers also need a WebTransport server you can reach: this showcase has no HTTP/3 server of its own, so the default endpoint is a public echo server. If your network blocks QUIC the attempt fails with the real error, shown verbatim — never a made-up result. Running your own server is a few lines; see the local echo server recipe.
Monitor a live session
Chosen tier
No decision yet.
the adaptation rule (in this page)
- Use 80% of
estimatedSendRateas the budget and pick the highest tier that fits. - If
estimatedSendRateisnull, hold the current tier — the spec says the member "can be null even if it was not null in previous results", so a null is "no information", not "zero bandwidth". - If
smoothedRttexceeds twiceminRttby more than 20 ms, queues are building: step down one tier even if the estimate looks fine. - Polling pauses while the tab is hidden (
visibilitychange) — no point spending wakeups on a monitor nobody sees.
code path
const TIERS = [["240p", 0.4e6], ["480p", 1.2e6], ["720p", 2.5e6], ["1080p", 5e6], ["4K", 16e6]];
setInterval(async () => {
const s = await transport.getStats();
if (s.estimatedSendRate === null) return; // no estimate: hold
const budget = s.estimatedSendRate * 0.8; // bits per second
let tier = TIERS.findLast(([, bps]) => bps <= budget) ?? TIERS[0];
if (s.smoothedRtt > 2 * s.minRtt + 20) tier = stepDown(tier); // queueing
encoder.configure({ ...config, bitrate: tier[1] });
}, 500);