Check for Permission

Once you’ve registered the service worker, you’ll have global access to the Notification API. First, we need to ask the user permission to show notifications:

The requestPermission promise returns one of three values: granted , denied , or default .

Note: Safari Version 12.0.3 still uses callback to get the permission.

Unregister, then register the new service worker. A notification prompt will pop up. Grant the service worker the access it needs.

Handling notification permissions

Upon pressing allow, the browser will save the choice under your settings. At any given time we can revoke the notifications through the settings. Be sure not to abuse the notifications, otherwise, users will revoke permissions and never grant it again.

brave://settings/content/notifications?search=site+settings

In case you’re wondering, I’m using the Brave browser. It’s pretty much the same as Chrome but it blocks ads by default and doesn’t have trackers. If you’re not using a Chromium-based browser, a quick search will tell you how to access the notifications settings.