WorkerLocation.pathname returns the pathname part of the worker’s location as a string—the path only (no scheme, host, query, or hash). Per MDN, on a docs URL it can be "/en-US/docs/Web".
Read the notes below before you rely on this property. Prefer feature detection when support is limited.
Syntax
Use location.pathname. Start with this line.
JavaScript
location.pathname
Call
What it does
location.pathname
Primary signature.
Built into Web Workers. Read self.location.pathname (or location.pathname) inside a worker — no import required.
Library declarations
JavaScript
location.pathname
Parameters
Parameter
Description
Worker context
Required. self.location is a WorkerLocation
Writable?
Optional. Read-only
Return Value
Return Value
Description
*
Path string (often starts with /)
JavaScript Examples
Example 1 — Read location.pathname
Post the worker pathname string (MDN idea).
JavaScript
// Inside a Web Worker
const result = self.location.pathname;
// e.g. "/en-US/docs/Web"
self.postMessage(result);
Blob URL. Object-URL workers use a blob: script address.
Protocol clue.location.protocol is typically "blob:".
Path shape. The pathname is often a UUID-style segment, not a docs path.
Debug tip. Pair pathname with href so you still see the full blob URL.
Compatibility
Browser Support
WorkerLocation.pathname 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.pathname
Supported across modern browsers with Web Workers. Read location.pathname 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.pathnameExcellent
Bottom line: Browser / Web Workers only — not a Node.js API. Expect MDN-style paths on http(s) scripts; blob demos usually print a UUID-style path.
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.