From the course: JavaScript: Progressive Web Applications

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Subscribing to push messaging

Subscribing to push messaging - JavaScript Tutorial

From the course: JavaScript: Progressive Web Applications

Start my 1-month free trial

Subscribing to push messaging

- [Instructor] Currently, our PWA asks users to allow notifications using the request permission method of the notification object. To subscribe to Push notifications, we need to call the subscribe method of the Push manager built into the browser. The service worker registration object provides an interface to the Push manager. Let's open main.js and then comment out the notification object detection conditional statement. So that was in the service worker registration. And here is the beginning of that conditional statement. So let's start a comment here. And then we'll need to end the comment beneath that curly bracket. Okay, so right now we're not going to be getting notifications. We've turned that off. Let's do this: just above that commented code, let's make a call to a function called subscribeToPush. And we'll write that in just a moment. All right, so now let's put in subcribeToPush. I'll put that down at the bottom of the page. And let me scroll up to give you guys a little…

Contents