JavaScript WorkerLocation protocol Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

The protocol property of a WorkerLocation object returns the protocol (scheme) of the worker’s location as a string. Learn self.location.protocol, the trailing colon, how it differs from origin and href, 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

Introduction

A protocol (also called a scheme) is the first part of a URL—like https:, http:, or blob:. Inside a worker, self.location.protocol returns that scheme for the worker script URL, including the trailing colon.

MDN’s classic idea: on a worker related to an https page, location.protocol can look like "https:".

💡
Beginner tip

Always compare with the colon included: location.protocol === "https:"—not "https". For the full URL, use href.

Understanding the protocol Property

A read-only instance property on WorkerLocation that returns the worker’s protocol as a string.

  • Value — a string with a trailing colon (e.g. "https:", "blob:").
  • vs origin — protocol is only the scheme; origin adds host and port.
  • Accessself.location.protocol or location.protocol inside the worker.
  • Workers only — not available on the main document thread.
  • Baseline Widely available on MDN (since July 2015).

📝 Syntax

Read the property inside a worker script:

JavaScript
const result = self.location.protocol;
// e.g. "https:"

Value

A string.

Typical pattern (MDN idea)

JavaScript
// Inside a Web Worker
const result = self.location.protocol;
self.postMessage(result);

⚡ Quick Reference

GoalCode / note
Read protocolself.location.protocol
Return typeString
MDN example shape"https:"
Check httpslocation.protocol === "https:"
Send to mainself.postMessage(location.protocol)
MDN statusBaseline Widely available (since July 2015)

🔍 At a Glance

Four facts to remember about WorkerLocation.protocol.

Returns
protocol

String

Where
in worker

self.location

Writable
no

Read-only

Baseline
widely

Since Jul 2015

Examples Gallery

Examples follow MDN WorkerLocation.protocol. Labs use blob workers and compare protocol with related URL parts.

📚 Getting Started

Read the protocol the MDN way.

Example 1 — Read self.location.protocol (MDN Idea)

Post the worker protocol string to the main thread.

JavaScript
const result = self.location.protocol;
// e.g. "https:"
self.postMessage(result);
Try It Yourself

How It Works

The try-it lab posts the live blob worker’s protocol plus the MDN sample string for comparison.

Example 2 — protocol vs origin vs href

Protocol is only the scheme; origin and href include more.

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

How It Works

Use protocol for scheme checks; use origin for security boundaries; use href for the full URL.

📈 Blob & Checks

See blob protocols and simple scheme checks.

Example 3 — Blob Worker Protocol

Log protocol together with href for blob workers.

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

How It Works

These try-it labs use blob workers, so you usually see "blob:"—not MDN’s "https:" sample.

Example 4 — Is It https:?

Compare the protocol string carefully (include the colon).

JavaScript
self.postMessage({
  protocol: location.protocol,
  isHttps: location.protocol === "https:",
  isHttp: location.protocol === "http:"
});
Try It Yourself

How It Works

A dedicated https worker would report isHttps: true. Blob demos report neither http nor https.

Example 5 — Worker Protocol vs Page Protocol

Post the worker protocol; compare it with window.location.protocol.

JavaScript
// Worker
self.postMessage(location.protocol);

// Main
worker.onmessage = (e) => {
  console.log("worker:", e.data);
  console.log("page:", location.protocol);
};
Try It Yourself

How It Works

The page protocol follows your site (http: or https:); the blob worker protocol is usually blob:.

🚀 Common Use Cases

  • Log the worker scheme for debugging panels.
  • Detect blob workers with protocol === "blob:".
  • Compare worker protocol with the page protocol.
  • Pair with origin and href when diagnosing URLs.
  • Teach URL scheme concepts using workers.

🔧 How It Works

1

Worker URL

Main creates a Worker with an http(s), blob, or other script URL.

URL
2

WorkerLocation

Inside the worker, self.location describes that absolute script URL.

API
3

Read protocol

location.protocol returns the scheme string with a trailing colon.

Read
4

Use or post

Compare, log, or postMessage the protocol to the main thread.

📝 Notes

  • MDN: Baseline Widely available (since July 2015) — no Deprecated / Experimental / Non-standard banner.
  • Only available in Web Workers (WorkerLocation / self.location).
  • Read-only string; includes the trailing colon.
  • Blob workers usually report "blob:".
  • Related learning: port, origin, href, Worker().

Universal Browser Support

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

Returns the worker's protocol as a string (with trailing colon). Read it with self.location.protocol inside a worker.

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Limited / legacy workers path (prefer modern browsers)
Legacy
WorkerLocation.protocol Excellent

Bottom line: Read location.protocol inside the worker—compare with "https:" or "blob:", and pair with origin/href when debugging.

Conclusion

WorkerLocation.protocol is the worker-side scheme string (with a trailing colon) for the script URL. Read it inside the worker, compare carefully with "https:" or "blob:", and use origin / href when you need more than the scheme.

Continue with search, port, origin, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Read protocol only inside a worker
  • Compare with the colon: "https:", "blob:"
  • Compare with window.location.protocol on the main thread
  • Log href alongside protocol for blob workers
  • Use postMessage to surface the value on the page

❌ Don’t

  • Expect WorkerLocation on the main thread
  • Assign to location.protocol in a worker (read-only)
  • Compare against "https" without the colon
  • Assume blob demos always match MDN’s https: example
  • Confuse protocol with the full origin string

Key Takeaways

Knowledge Unlocked

Five things to remember about WorkerLocation.protocol

The worker script’s scheme, as a string with a colon.

5
Core concepts
⚙️02

Workers

self.location

Context
🔒03

Read-only

no assign

Rule
📄04

Colon

https: not https

Gotcha
🎯05

Baseline

since Jul 2015

Status

❓ 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.
Did you know?

MDN’s example returns https: with the colon. That same trailing-colon rule applies to http:, blob:, and other schemes—so always include it in string comparisons.

Next: WorkerLocation.search

Learn how to read the worker's query string.

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.

5 people found this page helpful