JavaScript WorkerLocation href Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

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
CallWhat it does
location.hrefPrimary signature.

Built into Web Workers. Read self.location.href (or location.href) inside a worker — no import required.

Library declarations
JavaScript
location.href

Parameters

ParameterDescription
Worker contextRequired. self.location is a WorkerLocation
Writable?Optional. Read-only (unlike page location.href)

Return Value

Return ValueDescription
*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);
Try It Yourself

How It Works

  1. Worker context. Inside the worker, self.location is a WorkerLocation.
  2. Read href. location.href returns the complete serialized script URL.
  3. MDN shape. On an https docs URL, you get that full https string.
  4. Blob labs. Try-it demos use blob workers, so you often see a blob:… URL instead.

Example 2 — Blob href When Host Is Empty

Blob workers still expose a useful full URL via href.

JavaScript
self.postMessage({
  href: location.href,
  isBlob: location.href.indexOf("blob:") === 0,
  hostnameEmpty: location.hostname === ""
});
Try It Yourself

How It Works

  1. Blob URL. Object-URL workers run from a blob: script address.
  2. Empty hostname. hostname is often "" on blobs—not a failure.
  3. href still works. The full blob:… string is available on href.
  4. Best for logging. Prefer href when you need “which script URL is this worker?”

Example 3 — href vs toString()

Confirm they return the same serialized worker URL string.

JavaScript
self.postMessage({
  viaHref: location.href,
  viaToString: location.toString(),
  same: location.href === location.toString()
});
Try It Yourself

How It Works

  1. Read both forms. href is the property; toString() is the stringifier.
  2. Compare with ===. They should be the exact same string.
  3. MDN synonym. Prefer href for a clear property name in everyday code.
  4. Use either. Teaching stringifiers? Show toString(); logging URLs? Use href.

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 Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Android WebView Supported · Modern WebView
Full support
WorkerLocation.href Excellent

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.

Next: origin

Read the worker’s origin (scheme + host + port).

origin property →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful