web api instance method
PushSubscription: toJSON() method
Secure contextAvailable in workers
The toJSON() method of the PushSubscription interface is a
standard serializer: it returns a JSON representation of the subscription properties,
providing a useful shortcut.
Syntax
toJSON()
Parameters
None.
Return value
A JSON object. It contains the subscription endpoint, expirationTime and public keys, as an
endpoint member, an expirationTime member and a keys member.
Examples
navigator.serviceWorker.ready.then((reg) => {
reg.pushManager.getSubscription().then((subscription) => {
const mySubscription = subscription.toJSON();
// do something with subscription details
});
});
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.