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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With