How to handle pushsubscriptionchange event in push notifications service worker?

Viewed 53

How can we update subscription in chrome? As of today chrome does not listen to pushnotificationchange event. So code below will not work in case of chrome.

code taken from: https://pushpad.xyz/service-worker.js

self.addEventListener('pushsubscriptionchange', function(event) {
  event.waitUntil(
    fetch('https://pushpad.xyz/pushsubscriptionchange', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        old_endpoint: event.oldSubscription ? event.oldSubscription.endpoint : null,
        new_endpoint: event.newSubscription ? event.newSubscription.endpoint : null,
        new_p256dh: event.newSubscription ? event.newSubscription.toJSON().keys.p256dh : null,
        new_auth: event.newSubscription ? event.newSubscription.toJSON().keys.auth : null
      })
    })
  );
});

Chrome issue link: https://bugs.chromium.org/p/chromium/issues/detail?id=753163

0 Answers
Related