PushMessageData
Baseline 2023Newly available
Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
PushMessageData
はプッシュ API のインターフェイスで、さまざまな形式でサーバーから送信されるプッシュテータを取得する方法を提供します。
フェッチ API の同様のメソッドが 1 回しか呼び出せないのと異なり、これらは複数回呼び出せます。
プッシュ API を通して受け取ったメッセージはプッシュサービスによって暗号化されて送信され、PushMessageData
インターフェイスのメソッドで利用可能になる前にブラウザーによって自動的に復号されます。
インスタンスプロパティ
なし。
インスタンスメソッド
PushMessageData.arrayBuffer()
-
データを
ArrayBuffer
オブジェクトとして抜き出します。 PushMessageData.blob()
-
データを
Blob
オブジェクトとして抜き出します。 PushMessageData.json()
-
データを JSON オブジェクトとして抜き出します。
PushMessageData.text()
-
データをプレーンテキスト文字列として抜き出します。
例
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);
}
});
仕様書
Specification |
---|
Push API # pushmessagedata-interface |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
PushMessageData | ||||||||||||
arrayBuffer | ||||||||||||
blob | ||||||||||||
bytes | ||||||||||||
json | ||||||||||||
text |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- In development. Supported in a pre-release version.
- In development. Supported in a pre-release version.
- No support
- No support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.