Managing the user's subscription

In the example code, if the subscription object does not exist, the subscribeUser function is invoked. The service worker registration object is passed as the only parameter:

registration.pushManager.getSubscription().then(function (subscription) {            if(subscription === null){                  subscribeUser(registration);            }      });

The pushManager subscribe method has a single parameter, an object with two properties, userVisibleOnly and applicationServerKey.

The subscribe function returns a promise that resolves after the user has granted permission to send notifications and the browser sends a request to the push service.

As part of the subscribe function work flow, the User Agent is required to prompt the user for permission. ...

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.