I have two subdomains: https://abc.xxxx.com and https://xyz.xxxx.com. So my questions:
1). is it possible to register a service worker for https://xyz.xxxx.com from https://abc.xxxx.com ? if yes then how?
2). if http://abc.xxxx.com (http insecure) then anyway to register a service worker for https://xyz.xxxx.com from http://abc.xxxx.com like in iframe or something....
This is a real situation, I am facing for my multiple subdomain. Any help appreciated. Thanks in advance.
Try use Ngnix proxy_pass. This work for me.
Here are some general answers that I think should address the various points you raise in your question:
Each registered service worker has an associated
scope
, which dictates the set of web pages that the service worker can control. Thescope
of a service worker is a URL, and that URL must have the same origin as the page that registers the service worker, and must be either a URL that corresponds to the same path level as the page or a path that's one or more levels down. The defaultscope
corresponds to the same path level as location of the service worker script. Because of this restriction, it's not possible to callnavigator.serviceWorker.register(...)
from a page on one (sub-)domain and end up with a service worker that controls pages on another (sub-)domain.There are restrictions in place to prevent you from throwing an
https:
<iframe>
on anhttp:
page and using that to register a service worker. See DOMException when registering service worker inside an https iframeThough I don't know that it's directly related to your question, explicitly calling
fetch()
for anhttp:
resource within your service worker code will result in a failure in current versions of Chrome, since mixed-contentfetch()
s are not allowed within a service worker. I don't know if things are 100% settled on that front, and this open bug is still relevant.If you have pages that live on both
abc.123.com
andxyz.123.com
and you want both sets of pages to be controlled by a service worker, then you need to have two separate service worker registrations. Each registration needs to be for a copy of your service worker JS file that's hosted on the respective domain corresponding to the top-level page, and all pages and service worker scripts need to be accessed viahttps:
.That being said, you can kick off a service worker registration for a different domain by including a cross-domain
<iframe>
on a page, but both the host page and the<iframe>
need to be served viahttps:
. The normal service worker scoping restrictions apply, so if, for example, you want to register a service worker for the other domain that will cover the entirehttps://other-domain.com/
scope, you need to make sure that the location of the service worker script being registered is at the top-level, e.g.https://other-domain.com/service-worker.js
, not athttps://other-domain.com/path/to/service-worker.js
. This is the approach used by, for example, the AMP project via the<amp-install-serviceworker>
element.My bad, I misunderstood a bit. Well, here's the code
then here's the event -ish for your subscribe / unsubscribe
after that you need to register an account on the google developer console and register a project for something like *.xxxx.com . Then you need to get a proper manifest json with gcm_sender_id and gcm_user_visible_only
You need to create a key for both server and browser applications, there's more info on that on this page.
https://developers.google.com/web/updates/2015/03/push-notificatons-on-the-open-web?hl=en
The one for browser applications goes in your manifest json.
Then to send out push notifications you'll be using something like this:
And no, I don't know what issue you've been having but this works for me with multiple sub domains. :)
Service Worker scripts must be hosted at the same origin (Protocol + Domain name + Port).
Each sub-domain is considered a different origin, So, you will need to register a service worker for each one. Each of these workers will have its owncache
andscope
.