The origin property of a WorkerLocation object returns the worker’s origin as a string. Learn self.location.origin, how it differs from href and host, and what blob workers report—with five examples and try-it labs.
01
Kind
Instance property
02
Returns
String
03
Access
self.location
04
Writable?
Read-only
05
Context
Web Workers only
06
Status
Baseline widely
Fundamentals
Introduction
An origin is the combination of scheme, host, and port that defines a security boundary on the web. Inside a worker, self.location.origin returns that origin for the worker script URL.
MDN’s classic idea: on a page like the MDN docs site, self.location.origin can look like "https://developer.mozilla.org:443".
💡
Beginner tip
origin has no path, query, or hash. For the full worker URL string, use href.
Concept
Understanding the origin Property
A read-only instance property on WorkerLocation that returns the worker’s origin as a string.
Value — a string (origin form).
vs href — origin omits path, search, and hash.
Access — self.location.origin or location.origin inside the worker.
Workers only — not available on the main document thread.
Baseline Widely available on MDN (since September 2016).
Foundation
📝 Syntax
Read the property inside a worker script:
JavaScript
const result = self.location.origin;
// e.g. "https://developer.mozilla.org:443"
Value
A string.
Typical pattern (MDN idea)
JavaScript
// Inside a Web Worker
const result = self.location.origin;
self.postMessage(result);
Compare
⚖️ origin vs Related Ideas
Idea
Meaning
location.origin
Worker origin string
location.href
Full serialized worker URL
location.host
Hostname + port when shown
location.protocol
Scheme only
window.location.origin
Origin of the page (main thread)
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Read origin
self.location.origin
Return type
String
MDN example shape
"https://developer.mozilla.org:443"
Send to main
self.postMessage(location.origin)
MDN status
Baseline Widely available (since September 2016)
Snapshot
🔍 At a Glance
Four facts to remember about WorkerLocation.origin.
Returns
origin
String
Where
in worker
self.location
Writable
no
Read-only
Baseline
widely
Since Sep 2016
Hands-On
Examples Gallery
Examples follow MDN WorkerLocation.origin. Labs use blob workers and compare origin with related URL parts.
📚 Getting Started
Read the origin the MDN way.
Example 1 — Read self.location.origin (MDN Idea)
Post the worker origin string to the main thread.
JavaScript
const result = self.location.origin;
// e.g. "https://developer.mozilla.org:443"
self.postMessage(result);
WorkerLocation.origin is marked Baseline Widely available on MDN (since September 2016). Logos use the shared browser-image-sprite.png sprite from this project. It is only available in Web Workers.
✓ Baseline · Widely available
WorkerLocation.origin
Returns the worker's origin as a string. Read it with self.location.origin 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 ExplorerLimited / legacy workers path (prefer modern browsers)
Legacy
WorkerLocation.originExcellent
Bottom line: Read location.origin inside the worker—compare with the page origin, and pair with href when debugging blob workers.
Wrap Up
Conclusion
WorkerLocation.origin is the worker-side origin string for the script URL. Read it inside the worker, compare it with the page when needed, and use href when you need the full URL.
Compare with window.location.origin on the main thread
Log href alongside blob origins
Use postMessage to surface the value on the page
Treat opaque / unexpected origins carefully
❌ Don’t
Expect WorkerLocation on the main thread
Assign to location.origin in a worker (read-only)
Confuse origin with the full href
Assume blob demos always match MDN’s https example
Use origin alone when you need path or query details
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about WorkerLocation.origin
The worker script’s origin, as a string.
5
Core concepts
🔗01
Returns
origin string
API
⚙️02
Workers
self.location
Context
🔒03
Read-only
no assign
Rule
📄04
vs href
no path/hash
Compare
🎯05
Baseline
since Sep 2016
Status
❓ Frequently Asked Questions
A string: the worker's origin (scheme + host + port in origin form). Access it inside a worker as self.location.origin or location.origin.
No. MDN marks WorkerLocation.origin as Baseline Widely available (since September 2016). It is not Deprecated, Experimental, or Non-standard. It is only available in Web Workers.
href is the full serialized worker URL (path, query, hash included). origin is only the origin part—no path or fragment.
Blob worker origins can look different from http(s) workers (sometimes the string "null" for an opaque origin, depending on the URL and browser). Always log origin together with href when debugging.
No. WorkerLocation.origin is read-only.
Same idea (URL origin), different object. Inside a worker you read WorkerLocation via self.location—not the page's Location.
Did you know?
MDN’s example shows a default HTTPS port in the origin string (:443. Some browsers serialize default ports differently for display—always trust the live location.origin value in your environment.