Read port. Many blob workers and default-port URLs return "".
Empty is a string. It is not null or undefined.
Check clearly. Use port === "" before treating it as a number.
Debug tip. Pair empty ports with href / protocol to explain why.
Compatibility
Browser Support
WorkerLocation.port 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.port
Supported across modern browsers with Web Workers. Read location.port 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.portExcellent
Bottom line: Browser / Web Workers only — not a Node.js API. Expect MDN-style ports on non-default http(s) URLs; default ports and blob demos often print "".
Frequently Asked Questions
A string: the port part of the worker’s location. Access it inside a worker as self.location.port or location.port.
No. MDN marks WorkerLocation.port as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is only available in Web Workers.
host is hostname plus port when the port is shown. port is only the port number as a string (or an empty string when the default port is used).
For default ports (such as 80 for http or 443 for https), location.port is often the empty string "". Non-default ports like 8080 or 3002 usually appear as "8080" or "3002".
Blob workers often report an empty port. Always log port together with host, hostname, and href when debugging.