Setting up push notifications

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 ...

Get Progressive Web Application Development by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.