WorkerLocation.toString() is the stringifier for a worker’s location. It returns a string containing the serialized worker script URL. Per MDN, it is a synonym for WorkerLocation.href.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call location.toString. Start with this line.
JavaScript
location.toString()
Call
What it does
location.toString()
Primary signature.
location.toString(...)
Call with the arguments your case needs.
Built into Web Workers. Call location.toString() inside a worker — no import required.
Library declarations
JavaScript
location.toString()
Parameters
Parameter
Description
Worker context
Required. self.location is a WorkerLocation
Return Value
Return Value
Description
*
Serialized URL string (same as href)
JavaScript Examples
Example 1 — Call location.toString()
Post the serialized worker URL string to the main thread (MDN idea).
JavaScript
// Inside a Web Worker
const result = self.location.toString();
self.postMessage(result);
Explicit call.location.toString() always returns the URL string clearly.
String() asks the object for a primitive string and typically uses the stringifier.
Concatenation ("" + location) also triggers string conversion.
Teaching tip. Prefer an explicit toString() or href in beginner code so the intent is obvious.
Compatibility
Browser Support
WorkerLocation.toString() 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.toString()
Supported across modern browsers with Web Workers. Synonym for location.href inside a 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.toString()Excellent
Bottom line: Browser / Web Workers only — not a Node.js API. Call location.toString() or location.href inside the worker—both serialize the worker script URL.
Frequently Asked Questions
A string with the serialized URL for the worker’s location—the same full URL string as WorkerLocation.href. Call it inside a worker as self.location.toString() or location.toString().
No. MDN marks WorkerLocation.toString() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is only available in Web Workers.
Yes. MDN documents toString() as a synonym for WorkerLocation.href—both give the serialized worker URL string.
No. Call location.toString() with no arguments.
When JavaScript needs a string—for example template literals, string concatenation, or String(location)—the stringifier can produce the same URL string.
WorkerLocation exists only in workers. On the page you use window.location.toString() / location.href instead—same idea, different object.