v155 · webtransport · datagrams
The write rules at the edges
The writeDatagrams algorithm has sharp edges the happy path never touches: the wrong chunk type must reject with TypeError, an oversized datagram must be silently discarded with a resolved promise, and createWritable must refuse a sendGroup that belongs to another transport. Each rule below runs for real and compares the observed outcome against the spec's required one.
Chrome targets the new writables for Chrome 155 (--enable-blink-features=WebTransportSendGroup,WebTransportDatagramsWritable, or chrome://flags/#enable-experimental-web-platform-features). The first two rules also govern the legacy single datagrams.writable, so on a pre-155 build this page runs them against that — labelled as such — rather than pretending nothing is testable.
Run the rules
Rule 1 — a datagram must be a BufferSource
spec 4.3: "If data is not a BufferSource object, then return a promise rejected with a TypeError."
Write the string "not bytes" →
not run yet
Rule 2 — oversized datagrams are discarded, not rejected
spec 4.3: "If datagrams.[[OutgoingMaxDatagramSize]] is less than data's [[ByteLength]], return a promise resolved with undefined." The datagram simply vanishes.
Read maxDatagramSize, then write a datagram twice that size →
not run yet
Rule 3 — a sendGroup must belong to the same transport
spec 5.2: "If sendGroup is not null, and sendGroup.[[Transport]] is not this.[[Transport]], throw a TypeError." (Needs createSendGroup + createWritable, so it only runs on a build with both.)
Create a group on transport A, pass it to createWritable on transport B →
not run yet
why the discard rule is a trap
Rule 2 surprises everyone: an oversized datagram does not throw, does not reject, does not warn — the write succeeds and the data evaporates. The spec chose this because datagrams are inherently lossy (the network may drop any of them), so the API drops what it cannot send rather than erroring a healthy stream. The practical consequence: check maxDatagramSize yourself and chunk above it; no error will tell you that you forgot.
const writer = dg.createWritable().getWriter(); // or dg.writable legacy
await writer.write("oops"); // rejects: TypeError (rule 1)
await writer.write(new Uint8Array(dg.maxDatagramSize * 2));
// ^ resolves undefined — and nothing was ever sent (rule 2)