WorkerLocation.href returns a string containing the serialized URL for the worker’s location—the full worker script address. Per MDN, it is the complete URL string (and toString() is a synonym).
Read the notes below before you rely on this property. Prefer feature detection when support is limited.
Syntax
Use location.href. Start with this line.
JavaScript
location.href
Call
What it does
location.href
Primary signature.
Built into Web Workers. Read self.location.href (or location.href) inside a worker — no import required.
Library declarations
JavaScript
location.href
Parameters
Parameter
Description
Worker context
Required. self.location is a WorkerLocation
Writable?
Optional. Read-only (unlike page location.href)
Return Value
Return Value
Description
*
Full serialized URL string
JavaScript Examples
Example 1 — Read location.href
Post the full serialized worker URL (MDN idea).
JavaScript
// Inside a Web Worker
const result = location.href;
self.postMessage(result);
Read both forms.href is the property; toString() is the stringifier.
Compare with ===. They should be the exact same string.
MDN synonym. Prefer href for a clear property name in everyday code.
Use either. Teaching stringifiers? Show toString(); logging URLs? Use href.
Compatibility
Browser Support
WorkerLocation.href is marked Baseline Widely available on MDN (since July 2015). It is only available in Web Workers — not in Node.js, Bun, or Deno.
✓ Baseline · Widely available
WorkerLocation.href
Supported across modern browsers with Web Workers. Read location.href inside the worker.
98%Browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
WorkerLocation.hrefExcellent
Bottom line: Browser / Web Workers only — not a Node.js API. Use href (or toString()) for the full worker script URL—including blob: demos.
Frequently Asked Questions
A string containing the serialized URL for the worker’s location—the full worker script URL. Access it inside a worker as self.location.href or location.href.
No. MDN marks WorkerLocation.href as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is only available in Web Workers.
href is the complete serialized URL. host / hostname / pathname / search / hash are individual pieces of that URL.
A blob: URL string such as blob:http://localhost:3002/<uuid>. Unlike host/hostname (often empty on blobs), href is still a useful full URL.
No. WorkerLocation.href is read-only. Assigning to it does not navigate the worker the way window.location.href can on a page.
On WorkerLocation, toString() is documented as a synonym for href—both give the serialized worker URL string.