Back to Content

PushMessageData: bytes() method

files/en-us/web/api/pushmessagedata/bytes/index.md

latest826 B
Original Source

{{APIRef("Push API")}}{{SecureContext_Header}}{{AvailableInWorkers("service")}}

The bytes() method of the {{domxref("PushMessageData")}} interface extracts push message data as a {{jsxref("Uint8Array")}} object.

Syntax

js-nolint
bytes()

Parameters

None.

Return value

A {{jsxref("Uint8Array")}}.

Exceptions

The returned {{jsxref("Uint8Array")}} is backed by an {{jsxref("ArrayBuffer")}} of bytes. Exceptions thrown during creation of this backing buffer are re-thrown.

See TypedArray.

Examples

js
self.addEventListener("push", (event) => {
  const buffer = event.data.bytes();

  // do something with your typed array
});

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}