July 2018
Intermediate to advanced
354 pages
8h 51m
English
To enable push notifications, there are several steps you need to follow. The first step is detecting if the browser supports push or not. If so, then you can proceed:
navigator.serviceWorker.register('/sw.js').then(function (registration) { if ("PushManager" in window) { //push is supported }});
Since push is something you would configure after you register the service worker, you can check for support once the service worker is registered. Just like checking for service worker support, you can check if the window object contains a reference to the PushManager.
The PushManager has three methods to manage a user's subscription status. The getSubscription method returns a promise that resolves a PushSubscription ...
Read now
Unlock full access