From the course: JavaScript: Progressive Web Applications
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Requesting permission to show notifications - JavaScript Tutorial
From the course: JavaScript: Progressive Web Applications
Requesting permission to show notifications
- [Voiceover] Before we can display notifications, the user must first grant us permission. Fortunately, asking for permission is relatively straight forward. Because we eventually will call show notification method, on the service worker registration object, we need to wait until the promise that registers the service worker fulfills. Let's open main.js and add the code just below the line that writes the service workers scope to the console. That will ensure both service workers and notifications are supported. So if main.js isn't open, you can double click it in the js folder. Then move your cursor into the service worker registration block, and find where we wrote the scope of the service worker to the console, then you can hit enter and give yourself some room to work. So the first thing to do is to make sure that notifications are supported. That we can do in a simple conditional statement. So I'm gonna write if. So look for the notification object inside the window object. And…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
Introduction to notifications2m 21s
-
Requesting permission to show notifications5m 26s
-
Displaying a notification4m 50s
-
Adding data to a notification4m 36s
-
Closing a notification3m 33s
-
Handling the notification click event11m 25s
-
Push messaging overview1m 24s
-
Adding Firebase Cloud Messaging to the project2m 15s
-
Subscribing to push messaging6m
-
Handling push notifications3m 14s
-
Sending a tickle using cURL4m 57s
-
Sending data in a push message2m 9s
-
Installing Mozilla's Web Push library2m 51s
-
Modifying the push event handler2m 52s
-
Modifying the notification click event3m 48s
-
Creating the web push script6m
-
Testing the hosted app5m 7s
-
-
-