Ad

Service Worker And Page Permissions

If a service worker is associated to a web page, does it inherit its permissions (for example to show notifications)? Could I use a service worker to create notification?

Ad

Answer

In general it seems that service worker inherits page permissions, and you can use a service worker to create notifications, if your page has received permissions for that. On the other hand not everything is available to the service worker API. For example, Geolocation access has been proposed, but is apparently not yet available. So you'll have to look at things case-by-case.

Notifications are indeed one of the best use cases for service worker, since your service worker, once registered, can actually create notifications even if your page is not open in the user's browser. Here is an tutorial for push notifications with service workers in Chrome. You could also create notifications normally without the whole push part though. Just keep in mind that your service worker needs to be woken up by some event or other in order to do anything.

Ad
source: stackoverflow.com
Ad