PushSubscription: toJSON() メソッド

Baseline 2023
Newly available

Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

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

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
toJSON()

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.