JavaScript WorkerLocation origin Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

WorkerLocation.origin returns the worker’s origin as a string—scheme + host + port in origin form (no path, query, or hash). Per MDN, an example value is "https://developer.mozilla.org:443".

Read the notes below before you rely on this property. Prefer feature detection when support is limited.

Syntax

Use location.origin. Start with this line.

JavaScript
location.origin / self.location.origin
CallWhat it does
location.origin / self.location.originPrimary signature.

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

Library declarations
JavaScript
location.origin / self.location.origin

Parameters

ParameterDescription
Worker contextRequired. self.location is a WorkerLocation
Writable?Optional. Read-only

Return Value

Return ValueDescription
*Origin string (or special blob/opaque cases)

JavaScript Examples

Example 1 — Read location.origin

Post the worker origin string (MDN idea).

JavaScript
// Inside a Web Worker
const result = self.location.origin;
// e.g. "https://developer.mozilla.org:443"
self.postMessage(result);
Try It Yourself

How It Works

  1. Worker context. Inside the worker, self.location is a WorkerLocation.
  2. Read origin. location.origin returns the origin string only.
  3. MDN shape. An https docs host may look like "https://developer.mozilla.org:443".
  4. Blob labs differ. Try-it demos use blob workers, so the live origin can look different from that https sample.

Example 2 — origin vs href

See that origin drops the path while href keeps the full URL.

JavaScript
self.postMessage({
  origin: location.origin,
  href: location.href
});
Try It Yourself

How It Works

  1. Read both. origin and href come from the same location.
  2. href is complete. It includes protocol, path, and any query/hash.
  3. origin is trimmed. No path, search, or fragment.
  4. Pick the right one. Need security/origin checks? Use origin. Need the script URL? Use href.

Example 3 — Blob Worker Origin

Inspect origin, protocol, and href together for a blob worker.

JavaScript
self.postMessage({
  origin: location.origin,
  protocol: location.protocol,
  href: location.href
});
Try It Yourself

How It Works

  1. Blob URL. Object-URL workers use a blob: script address.
  2. Protocol clue. location.protocol is typically "blob:".
  3. Origin may be special. Some browsers expose an opaque origin as the string "null".
  4. Debug tip. Always pair origin with href so you still see the full blob URL.

Browser Support

WorkerLocation.origin is marked Baseline Widely available on MDN (since September 2016). It is only available in Web Workers — not in Node.js, Bun, or Deno.

✓ Baseline · Widely available

WorkerLocation.origin

Supported across modern browsers with Web Workers. Read location.origin 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.origin Excellent

Bottom line: Browser / Web Workers only — not a Node.js API. Expect MDN-style origins on http(s) scripts; blob demos may print a special origin string.

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.

Next: pathname

Read the path part of the worker script URL.

pathname 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