MDN self-hosted library · e01.org

PushSubscription: toJSON() method

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
navigator.serviceWorker.ready.then((reg) => {
  reg.pushManager.getSubscription().then((subscription) => {
    const json = subscription.toJSON();
    console.log(json); // A plain object
    console.log(typeof json); // "object"
    console.log(json.endpoint); // Same value as subscription.endpoint
  });
});
js
console.log(JSON.stringify(subscription));