JavaScript WorkerLocation protocol Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

WorkerLocation.protocol returns the protocol (scheme) part of the worker’s location as a string. Per MDN, on an https: worker page, location.protocol is "https:" (trailing colon included).

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

Syntax

Use location.protocol. Start with this line.

JavaScript
location.protocol
CallWhat it does
location.protocolPrimary signature.

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

Library declarations
JavaScript
location.protocol

Parameters

ParameterDescription
Worker contextRequired. self.location is a WorkerLocation
Trailing :Required. Use "https:", not "https"

Return Value

Return ValueDescription
*String ("https:", "blob:", ...)

JavaScript Examples

Example 1 — Read location.protocol

Post the worker protocol string (MDN idea: https:).

JavaScript
// Inside a Web Worker on an https: page
const result = self.location.protocol; // "https:"
self.postMessage(result);
Try It Yourself

How It Works

  1. Worker context. Inside the worker, self.location is a WorkerLocation.
  2. Read protocol. location.protocol returns the scheme as a string.
  3. MDN shape. On https pages, the value is "https:" (colon included).
  4. Blob labs differ. Try-it demos use blob workers, so the live protocol is often "blob:".

Example 2 — protocol vs origin

Compare protocol, origin, and href on the same worker location.

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

How It Works

  1. Three pieces. Read protocol, origin, and href from the same location.
  2. protocol is the scheme. Just "https:" or "blob:".
  3. origin adds host. Scheme + host + port in origin form.
  4. href is full. The complete serialized worker script URL.

Example 3 — Blob Protocol Check

Detect whether the worker was created from a blob URL.

JavaScript
self.postMessage({
  protocol: location.protocol,
  isBlob: location.protocol === "blob:"
});
Try It Yourself

How It Works

  1. Read protocol. Blob workers commonly return "blob:".
  2. Keep the colon. Compare with "blob:", not "blob".
  3. Flag clearly. protocol === "blob:" is a simple boolean check.
  4. Debug tip. Pair with href when the scheme looks unexpected.

Browser Support

WorkerLocation.protocol 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.protocol

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

Bottom line: Browser / Web Workers only — not a Node.js API. Expect MDN-style "https:" on https worker scripts; blob demos usually print "blob:".

Frequently Asked Questions

A string: the protocol (scheme) part of the worker’s location, usually with a trailing colon—for example "https:" or "blob:". Access it inside a worker as self.location.protocol or location.protocol.
No. MDN marks WorkerLocation.protocol as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is only available in Web Workers.
URL protocol strings conventionally include the trailing colon, so you get "https:" rather than "https". Compare with === "https:" when checking.
protocol is only the scheme (with colon). origin combines scheme, host, and port into one origin string.
Blob workers usually report "blob:". Always log protocol together with href when debugging.
No. WorkerLocation.protocol is read-only.

Next: search

Read the query string part of the worker script URL.

search 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