The host property of a WorkerLocation object returns the host part of the worker’s location. Learn self.location.host, how it relates to hostname and port, 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
Inside a Web Worker, self.location is a WorkerLocation for the worker script URL. host is the authority-style host string—usually hostname plus port when the port is shown (for example localhost:8080).
MDN’s classic example: for a worker on http://localhost:8080/, location.host returns "localhost:8080".
💡
Beginner tip
Blob-worker demos often show an emptylocation.host because blob: URLs do not use a normal hostname. That is expected—read protocol and href together.
Concept
Understanding the host Property
A read-only instance property on WorkerLocation that returns the host part of the worker’s location as a string.
Value — a string (for example "localhost:8080").
vs hostname — host may include the port; hostname does not.
Access — self.location.host or location.host 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 = location.host;
// e.g. "localhost:8080" on http://localhost:8080/
Value
A string.
Typical pattern (MDN idea)
JavaScript
// Inside a Web Worker on http://localhost:8080/
const result = location.host; // "localhost:8080"
self.postMessage(result);
Compare
⚖️ host vs Related Ideas
Idea
Meaning
location.host
Hostname + port when applicable
location.hostname
Hostname only (no port)
location.port
Port string alone
location.href
Full serialized worker URL
window.location.host
Host of the page URL (main thread)
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Read host
self.location.host
Return type
String
MDN example
"localhost:8080"
Blob workers
Often host === ""
Send to main
self.postMessage(location.host)
MDN status
Baseline Widely available (since July 2015)
Snapshot
🔍 At a Glance
Four facts to remember about WorkerLocation.host.
Returns
string
host[:port]
Where
in worker
self.location
Writable
no
Read-only
Baseline
widely
Since Jul 2015
Hands-On
Examples Gallery
Examples follow MDN WorkerLocation.host. Labs use blob workers (host may be empty) and compare related URL parts.
📚 Getting Started
Read the host the MDN way.
Example 1 — Read location.host (MDN Idea)
On an HTTP worker URL like http://localhost:8080/, host includes the port.
JavaScript
// On http://localhost:8080/
const result = location.host; // "localhost:8080"
self.postMessage(result);
WorkerLocation.host 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.host
Returns the host part of the worker's location as a string. Read it with self.location.host 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 ExplorerWorkers / WorkerLocation in IE10+ (prefer modern browsers)
Legacy
WorkerLocation.hostExcellent
Bottom line: Read location.host inside the worker—expect an empty string for many blob: demos, and localhost:port for typical http(s) worker scripts.
Wrap Up
Conclusion
WorkerLocation.host is the worker-side host string for the script URL—often hostname:port for http(s) workers. Remember blob workers may report an empty host, and always read it inside the worker (then post if the UI needs it).
Confuse page window.location.host with the worker’s host
Assume blob demos always match MDN’s localhost example
Parse IPv6 hosts with naive split(":") only
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about WorkerLocation.host
The host part of the worker script URL, as a string.
5
Core concepts
🔗01
Returns
host string
API
⚙️02
Workers
self.location
Context
🔒03
Read-only
no assign
Rule
📄04
vs hostname
may include port
Compare
🎯05
Baseline
since Jul 2015
Status
❓ Frequently Asked Questions
A string: the host part of the worker's location URL—typically hostname plus port when the port is non-default (for example "localhost:8080"). Access it inside a worker as self.location.host or location.host.
No. MDN marks WorkerLocation.host as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is only available in Web Workers.
hostname is just the name (for example "localhost"). host is hostname plus port when applicable (for example "localhost:8080"). Prefer host when you need the full authority string.
blob: worker URLs often have an empty host. That is normal. MDN's localhost:8080 example applies to http(s) worker script URLs. Always check location.protocol and location.href too.
No. WorkerLocation.host is read-only. You cannot rewrite the worker URL by assigning to host.
Same idea (URL host), different object. Inside a worker you read WorkerLocation via self.location—not the page's Location.
Did you know?
Default ports (80 for HTTP, 443 for HTTPS) are often omitted from host. Non-default ports like 8080 or 3002 usually appear after a colon—exactly like MDN’s localhost:8080 example.