How to register a service worker from another domain

I am trying to implement Push Notifications for Google Chrome. I want to register a service worker from another domain.

Example: The Service Worker code is located at: https://example.com/

I want to register a service worker (who is in the specified domain) from another domain: https://example2.com/

Is there any way to achieve the same. Because when I try to include the working user page (example) as an iFrame, the working service throws an error when registering

"Unprepared (in promise) DOMException: Registration error - permission denied"

+4
source share
1 answer

This is not possible, since an exception SecurityErrorwill be included in the rejected promise if the origin of the scriptURL is not a client. See the Specification in the Registration Algorithm .

Even if this is possible, there would be few advantages, since the service scopeURL should have the same origin as the page that registers the service worker.

There are restrictions in iFrame to prevent you from choosing https: on the http page and using this to register a worker. See DOMException when registering a service worker inside https iframe .

+2
source

Source: https://habr.com/ru/post/1619350/


All Articles