Cheatography
https://cheatography.com
Web-ServerSetup: | | Web Server Extension for Chrome: | |
Initialize StateSet the initial subscription value: | swRegistration.pushManager.getSubscription() .then(function(subscription) |
Handle a Push EventTriggering a push message: | self.addEventListener('push', function(event) |
Unsubscribe UserUnsubscribe Function: | swRegistration.pushManager.getSubscription() .then(function(subscription) { if (subscription) { return subscription.unsubscribe(); } |
| | Register a service workerRegister a service worker: | navigator.serviceWorker.register('sw.js').then(function(swReg) |
Handle Permission DeniedHandling permission denied: | if (Notification.permission === 'denied') |
Notification ClickAdd click event to notification: | self.addEventListener('notificationclick', function(event) |
Application Server keySet application server key: | const applicationServerPublicKey = '<Your Public Key>'; |
Subscribe UserHandle user subscription: | pushButton.addEventListener('click', function() { pushButton.disabled = true; if (isSubscribed) { // TODO: Unsubscribe user } else { subscribeUser(); } | Update Subscription: | updateSubscriptionOnServer(subscription); |
|
Help Us Go Positive!
We offset our carbon usage with Ecologi. Click the link below to help us!
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by Dominik Mihalic