PushSubscription.toJSON()

Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。

PushSubscription インターフェイスの toJSON() メソッドは、スタンダードなシリアライザーです:これは、便利なショートカットを提供するサブスクリプションプロパティの JSON 表記を返します。

構文

mySubscription = subscription.toJSON()

引数

なし。

返値

JSON オブジェクト。現在、endpoint メンバーとしてサブスクリプションエンドポイントのみを含みます。

navigator.serviceWorker.ready.then(function(reg) {
  reg.pushManager.getSubscription().then(function(subscription) {
    var mySubscription = subscription.toJSON();
    // サブスクリプションの詳細を使用して何かを実行する。
  })
});

仕様書

Specification
Push API
# dom-pushsubscription-tojson

ブラウザーの互換性

BCD tables only load in the browser

関連項目