This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Note: This feature is only available in Web Workers.
The WorkerLocation interface defines the absolute location of the script executed by the Worker. Such an object is initialized for each worker and is available via the WorkerGlobalScope.location property obtained by calling self.location.
This interface is only visible from inside a JavaScript script executed in the context of a Web worker.
WorkerLocation.href Read only
Returns a string containing the serialized URL for the worker's location.
WorkerLocation.protocol Read only
Returns the protocol part of the worker's location.
WorkerLocation.host Read only
Returns the host part of the worker's location.
WorkerLocation.hostname Read only
Returns the hostname part of the worker's location.
WorkerLocation.origin Read only
Returns the worker's origin.
WorkerLocation.port Read only
Returns the port part of the worker's location.
WorkerLocation.pathname Read only
Returns the pathname part of the worker's location.
WorkerLocation.search Read only
Returns the search part of the worker's location.
WorkerLocation.hash Read only
Returns the hash part of the worker's location.
WorkerLocation.toString()Returns a string containing the serialized URL for the worker's location. It is a synonym for WorkerLocation.href.
| Specification |
|---|
| HTML> # worker-locations> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
WorkerLocation |
4 | 12 | 3.5 | ≤12.1 | 4 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
hash |
4 | 12 | 3.5 | ≤12.1 | 4 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
host |
4 | 12 | 3.5 | ≤12.1 | 4 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
hostname |
4 | 12 | 3.5 | ≤12.1 | 4 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
href |
4 | 12 | 3.5 | ≤12.1 | 4 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
origin |
38 | 14 | 29 | 25 | 10 | 38 | 29 | 25 | 10 | 3.0 | 38 | 10 |
pathname |
4 | 12 | 3.5 | ≤12.1 | 4 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
port |
4 | 12 | 3.5 | ≤12.1 | 4 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
protocol |
4 | 12 | 3.5 | ≤12.1 | 4 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
search |
4 | 12 | 3.5 | ≤12.1 | 4 | 18 | 4 | ≤12.1 | 5 | 1.0 | 4.4 | 5 |
toString |
4 | 12 | 3.5 | ≤15 | 4 | 18 | 4 | ≤14 | 5 | 1.0 | 4.4 | 5 |
Worker, WorkerNavigator, and WorkerGlobalScope
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WorkerLocation