Skip to content

Latest commit

 

History

History
50 lines (32 loc) · 1013 Bytes

File metadata and controls

50 lines (32 loc) · 1013 Bytes
title PushMessageData: bytes() method
short-title bytes()
slug Web/API/PushMessageData/bytes
page-type web-api-instance-method
browser-compat api.PushMessageData.bytes

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

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

Syntax

bytes()

Parameters

None.

Return value

An {{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

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

  // do something with your typed array
});

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}