The href property of a WorkerLocation object returns a string containing the serialized URL for the worker’s location. Learn self.location.href, how it differs from pieces like host, and how blob workers expose blob: URLs—with five examples and try-it labs.
01
Kind
Instance property
02
Returns
String (full URL)
03
Access
self.location
04
Writable?
Read-only
05
Context
Web Workers only
06
Status
Baseline widely
Fundamentals
Introduction
Inside a Web Worker, self.location is a WorkerLocation for the worker script URL. href is the complete serialized form of that URL—the whole address as one string.
MDN’s classic idea: for a worker loaded from an https docs URL, location.href returns that full URL string. In our try-it labs, blob workers return a blob:… URL instead.
💡
Beginner tip
When host / hostname are empty on a blob worker, href is still the best property for logging “which script URL is this worker running?”
Concept
Understanding the href Property
A read-only instance property on WorkerLocation that returns the serialized URL of the worker’s location as a string.
Value — a string (the full worker script URL).
Synonym — WorkerLocation.toString() returns the same serialized URL.
Access — self.location.href or location.href inside the worker.
Workers only — not available on the main document thread.
Baseline Widely available on MDN (since July 2015).
Foundation
📝 Syntax
Read the property inside a worker script:
JavaScript
const result = location.href;
// full serialized worker URL string
Value
A string.
Typical pattern (MDN idea)
JavaScript
// Inside a Web Worker
const result = location.href;
// e.g. "https://developer.mozilla.org/en-US/docs/Web"
self.postMessage(result);
Compare
⚖️ href vs Related Ideas
Idea
Meaning
location.href
Full serialized worker URL
location.toString()
Same serialized URL (synonym)
location.protocol
Scheme only (https:, blob:, …)
location.pathname
Path only
window.location.href
Full URL of the page (main thread)
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Read href
self.location.href
Return type
String (full URL)
Parse parts
new URL(location.href)
Blob workers
Starts with blob:
Send to main
self.postMessage(location.href)
MDN status
Baseline Widely available (since July 2015)
Snapshot
🔍 At a Glance
Four facts to remember about WorkerLocation.href.
Returns
full URL
Serialized string
Where
in worker
self.location
Writable
no
Read-only
Baseline
widely
Since Jul 2015
Hands-On
Examples Gallery
Examples follow MDN WorkerLocation.href. Labs use blob workers so you always get a concrete full URL string.
📚 Getting Started
Read the full URL the MDN way.
Example 1 — Read location.href (MDN Idea)
Post the serialized worker URL to the main thread.
JavaScript
const result = location.href;
self.postMessage(result);
WorkerLocation.href is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. It is only available in Web Workers.
✓ Baseline · Widely available
WorkerLocation.href
Returns the serialized URL for the worker's location as a string. Read it with self.location.href inside a worker.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerWorkers / WorkerLocation in IE10+ (prefer modern browsers)
Legacy
WorkerLocation.hrefExcellent
Bottom line: Read location.href inside the worker for the full script URL—especially useful when host/hostname are empty on blob: workers.
Wrap Up
Conclusion
WorkerLocation.href is the full serialized worker script URL. Read it inside the worker, post it when the UI needs diagnostics, and prefer it over empty host values on blob workers.
The full serialized worker script URL, as a string.
5
Core concepts
🔗01
Returns
full URL string
API
⚙️02
Workers
self.location
Context
🔒03
Read-only
no assign
Rule
📄04
vs parts
whole URL
Compare
🎯05
Baseline
since Jul 2015
Status
❓ 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.
Did you know?
MDN documents WorkerLocation.toString() as a synonym for href. Both give you the same serialized worker URL string—handy when an API expects a stringifiable location object.