このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

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

ブラウザーの互換性