PushSubscription: toJSON() メソッド

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

ブラウザーの互換性

BCD tables only load in the browser