PushSubscription: toJSON() メソッド
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2023年3月.
toJSON()
は PushSubscription
インターフェイスの メソッドで、標準のシリアライザーです。これは、このサブスクリプションのプロパティの JSON 表現を返す、便利なショートカットを提供します。
構文
js
toJSON()
引数
なし。
返値
JSON オブジェクトです。現在は、endpoint
メンバーとしてサブスクリプションエンドポイントのみを含みます。
例
js
navigator.serviceWorker.ready.then((reg) => {
reg.pushManager.getSubscription().then((subscription) => {
const mySubscription = subscription.toJSON();
// サブスクリプションの詳細を使用して何かを実行する
});
});
仕様書
Specification |
---|
Push API> # dom-pushsubscription-tojson> |
ブラウザーの互換性
Loading…