Skip to content

Instantly share code, notes, and snippets.

@novaknole
Created April 30, 2020 16:21
Show Gist options
  • Save novaknole/bea8fe853e8b90357fb8565a17a2a094 to your computer and use it in GitHub Desktop.
Save novaknole/bea8fe853e8b90357fb8565a17a2a094 to your computer and use it in GitHub Desktop.
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
})
})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment