demo · v132

PushMessageData: all four reads compared

Synthesise a push payload and drain it four ways. .bytes() is the v132 addition — Uint8Array view, no double allocation.

methods on PushMessageData

methodreturnsnote
.text()stringUTF-8 decode
.json()parsed JSdecode + JSON.parse
.arrayBuffer()ArrayBufferraw bytes, needs typed-array wrap
.blob()Bloboctet-stream
.bytes() (v132)Uint8Arrayalready a view

synthesise & drain

click "drain"
// in your service worker
self.addEventListener("push", async (e) => {
  const data = e.data;
  if (!data) return;
  // pick the right one for your payload:
  const view = data.bytes();        // Uint8Array (v132)
  const text = data.text();         // string
  const json = data.json();         // parsed
  const blob = data.blob();         // Blob
  const buf  = data.arrayBuffer();  // ArrayBuffer
  // ...
});

see also