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
Fundamentals
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.
Concept
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.
Access — self.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).
Foundation
📝 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);
Compare
⚖️ protocol vs Related Ideas
Idea
Meaning
location.protocol
Scheme with trailing colon
location.origin
Scheme + host + port
location.href
Full serialized worker URL
location.host
Hostname + port when shown
window.location.protocol
Protocol of the page (main thread)
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Read protocol
self.location.protocol
Return type
String
MDN example shape
"https:"
Check https
location.protocol === "https:"
Send to main
self.postMessage(location.protocol)
MDN status
Baseline Widely available (since July 2015)
Snapshot
🔍 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
Hands-On
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);
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.
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.protocolExcellent
Bottom line: Read location.protocol inside the worker—compare with "https:" or "blob:", and pair with origin/href when debugging.
Wrap Up
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.
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
Summary
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
🔗01
Returns
scheme string
API
⚙️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.