Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. PushMessageData

PushMessageData

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨March 2023⁩.

* Some parts of this feature may have varying levels of support.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Note: This feature is only available inService Workers.

ThePushMessageData interface of thePush API provides methods which let you retrieve the push data sent by a server in various formats.

Unlike the similar methods in theFetch API, which only allow the method to be invoked once, these methods can be called multiple times.

Messages received through the Push API are sent encrypted by push services and then automatically decrypted by browsers before they are made accessible through the methods of thePushMessageData interface.

Instance properties

None.

Instance methods

PushMessageData.arrayBuffer()

Extracts the data as anArrayBuffer object.

PushMessageData.blob()

Extracts the data as aBlob object.

PushMessageData.bytes()

Extracts the data as aUint8Array object.

PushMessageData.json()

Extracts the data as aJSON object.

PushMessageData.text()

Extracts the data as a plain text string.

Examples

js
self.addEventListener("push", (event) => {  const obj = event.data.json();  if (obj.action === "subscribe" || obj.action === "unsubscribe") {    fireNotification(obj, event);    port.postMessage(obj);  } else if (obj.action === "init" || obj.action === "chatMsg") {    port.postMessage(obj);  }});

Specifications

Specification
Push API
# pushmessagedata-interface

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp