The pathname property of a WorkerLocation object returns the pathname of the worker’s location as a string. Learn self.location.pathname, how it differs from href, search, and hash, 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
A pathname is the path portion of a URL—everything after the host (and port), before the query string or hash. Inside a worker, self.location.pathname returns that path for the worker script URL.
MDN’s classic idea: on a worker loaded like the MDN docs path, location.pathname can look like "/en-US/docs/Web".
💡
Beginner tip
pathname has no query (search) or fragment (hash). For the full worker URL string, use href.
Concept
Understanding the pathname Property
A read-only instance property on WorkerLocation that returns the worker’s pathname as a string.
Value — a string (often starting with /).
vs href — pathname omits scheme, host, search, and hash.
Access — self.location.pathname or location.pathname 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 = self.location.pathname;
// e.g. "/en-US/docs/Web"
Value
A string.
Typical pattern (MDN idea)
JavaScript
// Inside a Web Worker
const result = self.location.pathname;
self.postMessage(result);
Compare
⚖️ pathname vs Related Ideas
Idea
Meaning
location.pathname
Worker path string
location.href
Full serialized worker URL
location.search
Query string (starts with ? when present)
location.hash
Fragment (starts with # when present)
location.origin
Scheme + host + port (no path)
window.location.pathname
Path of the page (main thread)
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Read pathname
self.location.pathname
Return type
String
MDN example shape
"/en-US/docs/Web"
Send to main
self.postMessage(location.pathname)
MDN status
Baseline Widely available (since July 2015)
Snapshot
🔍 At a Glance
Four facts to remember about WorkerLocation.pathname.
Returns
pathname
String
Where
in worker
self.location
Writable
no
Read-only
Baseline
widely
Since Jul 2015
Hands-On
Examples Gallery
Examples follow MDN WorkerLocation.pathname. Labs use blob workers and compare pathname with related URL parts.
📚 Getting Started
Read the pathname the MDN way.
Example 1 — Read self.location.pathname (MDN Idea)
Post the worker pathname string to the main thread.
JavaScript
const result = self.location.pathname;
// e.g. "/en-US/docs/Web"
self.postMessage(result);
WorkerLocation.pathname 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.pathname
Returns the worker's pathname as a string. Read it with self.location.pathname 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.pathnameExcellent
Bottom line: Read location.pathname inside the worker—compare with the page path, and pair with href when debugging blob workers.
Wrap Up
Conclusion
WorkerLocation.pathname is the worker-side path 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.pathname on the main thread
Log href alongside blob pathnames
Use postMessage to surface the value on the page
Pair with search and hash when parsing URLs
❌ Don’t
Expect WorkerLocation on the main thread
Assign to location.pathname in a worker (read-only)
Confuse pathname with the full href
Assume blob demos always match MDN’s http(s) path example
Expect query or hash inside pathname
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about WorkerLocation.pathname
The worker script’s path, as a string.
5
Core concepts
🔗01
Returns
path string
API
⚙️02
Workers
self.location
Context
🔒03
Read-only
no assign
Rule
📄04
vs href
path only
Compare
🎯05
Baseline
since Jul 2015
Status
❓ Frequently Asked Questions
A string: the pathname part of the worker's location. Access it inside a worker as self.location.pathname or location.pathname.
No. MDN marks WorkerLocation.pathname 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 full serialized worker URL. pathname is only the path segment—no scheme, host, query, or hash.
Blob worker pathnames often look like a UUID-style path under a blob: URL—not like an http(s) docs path. Always log pathname together with href when debugging.
No. WorkerLocation.pathname is read-only.
Same idea (URL path), different object. Inside a worker you read WorkerLocation via self.location—not the page's Location.
Did you know?
MDN’s example uses a docs-style path (/en-US/docs/Web. Blob workers in these try-it labs usually show a UUID-style pathname instead—same property, different URL shape.