PushSubscription: toJSON()-Methode

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.

Sicherer Kontext: Diese Funktion ist nur in sicheren Kontexten (HTTPS) in einigen oder allen unterstützenden Browsern verfügbar.

Hinweis: Diese Funktion ist in Web Workers verfügbar.

Die toJSON()-Methode der PushSubscription-Schnittstelle ist ein standardmäßiger Serializer: Sie gibt eine JSON-Darstellung der Abonnementseigenschaften zurück und bietet damit eine nützliche Abkürzung.

Syntax

js
toJSON()

Parameter

Keine.

Rückgabewert

Ein JSON-Objekt. Es enthält den Abonnement-Endpunkt, expirationTime und öffentliche Schlüssel als ein endpoint-Mitglied, ein expirationTime-Mitglied und ein keys-Mitglied.

Beispiele

js
navigator.serviceWorker.ready.then((reg) => {
  reg.pushManager.getSubscription().then((subscription) => {
    const mySubscription = subscription.toJSON();
    // do something with subscription details
  });
});

Spezifikationen

Specification
Push API
# dom-pushsubscription-tojson

Browser-Kompatibilität

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.