demo · v138

pushsubscriptionchange on resubscription

Drive the lifecycle below. Before 138, the SW only got pushsubscriptionchange on revocation. Now it also fires when a fresh subscription is minted after a permission restore — so your server-side sync can happen at the same moment in both directions.

old subscription endpoint

new subscription endpoint

the code

self.addEventListener("pushsubscriptionchange", (e) => {
  // 138+: now also fires when a fresh subscription is granted
  // after a permissions-restore. Use it to:
  //   - send the new endpoint to your server
  //   - revoke the old endpoint
  console.log({ old: e.oldSubscription, new: e.newSubscription });
});

see also