Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the hostname where the service worker is installed?

Usually in javascript you can find the hostname using window.location.hostname, but it seems in service workers you cannot find the hostname using this method.

Is there any other elegant way to get the hostname dynamically?

like image 533
Shashank Avatar asked Jul 25 '16 13:07

Shashank


1 Answers

Code running in the context of a service worker can get the relevant hostname via self.location.hostname.

If you'd like to explore more of what's available inside of a service worker, the relevant documentation is for the ServiceWorkerGlobalScope.

Specifically, you'll see that the ServiceWorkerGlobalScope inherits from WorkerGlobalScope, and that, in turn, exposes a read-only location property.

like image 58
Jeff Posnick Avatar answered Oct 24 '22 00:10

Jeff Posnick