v132 · capabilities (fugu)

PushMessageData::bytes()

The PushMessageData interface mimics the Body interface, which was amended earlier this year with a new bytes() method, following the principle that APIs should generally vend byte buffers as Uint8Arrays.

concepts

  1. PushMessageData.bytes()

    PushMessageData.bytes() returns a Uint8Array. Cleaner than the arrayBuffer() detour for binary push payloads.

  2. service worker integration

    Register a real SW; round-trip a payload through postMessage using the same decode path a real push event would use.

  3. method comparator

    Synthesise a text, JSON, or binary push payload. Drain it via every PushMessageData method side-by-side: text(), json(), arrayBuffer(), bytes().

  4. Binary Protocol Demo

    Design a compact push protocol with header, payload, and checksum. Build a binary packet byte-by-byte and watch the service worker decode it using bytes() vs the old arrayBuffer() approach.

why it shipped

(Re)align with the `Body` interface by providing the `bytes()` accessor on the `PushMessageData` interface as well. Today this can be done by obtaining the `arrayBuffer()` and then creating a Uint8 view based on it, however a principle was introduced that agreed we should make this the well lit path: https://github.com/w3ctag/design-principles/pull/480

references