WorkerLocation.host returns the host part of the worker’s location as a string—usually hostname plus port when shown. Per MDN, on http://localhost:8080/, location.host is "localhost:8080".
Read the notes below before you rely on this property. Prefer feature detection when support is limited.
Syntax
Use location.host. Start with this line.
JavaScript
location.host
Call
What it does
location.host
Primary signature.
Built into Web Workers. Read self.location.host (or location.host) inside a worker — no import required.
Library declarations
JavaScript
location.host
Parameters
Parameter
Description
Worker context
Required. self.location is a WorkerLocation
Return Value
Return Value
Description
*
String ("host:port" or "")
JavaScript Examples
Example 1 — Read location.host
Post the host string (MDN idea: localhost:8080 on http workers).
JavaScript
// Inside a Web Worker on http://localhost:8080/
const result = location.host; // "localhost:8080"
self.postMessage(result);
host: ""
hostname: ""
port: ""
(on http://localhost:8080 → host "localhost:8080", hostname "localhost", port "8080")
How It Works
Three pieces. Read host, hostname, and port from the same location.
host combines. When a port is shown, host looks like hostname:port.
hostname is bare. No port number in hostname.
Pick the right one. Need authority? Use host. Need name or port alone? Use those properties.
Compatibility
Browser Support
WorkerLocation.host 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.host
Supported across modern browsers with Web Workers. Read location.host inside the worker.
98%Browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
Android WebViewSupported · Modern WebView
Full support
WorkerLocation.hostExcellent
Bottom line: Browser / Web Workers only — not a Node.js API. Expect MDN-style hosts on http(s) scripts; blob demos often print an empty host.
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.