The toString() stringifier method of a WorkerLocation object returns a string containing the serialized URL for the worker’s location. MDN documents it as a synonym for WorkerLocation.href. Learn when to call it, how it matches href, and how string coercion works—with five examples and try-it labs.
01
Kind
Instance method
02
Returns
String
03
Params
None
04
Synonym
href
05
Context
Web Workers only
06
Status
Baseline widely
Fundamentals
Introduction
Inside a worker, self.location is a WorkerLocation object that describes the worker script URL. Calling location.toString() turns that object into the full serialized URL string—the same value as location.href.
MDN’s classic idea: on a worker related to https://developer.mozilla.org/en-US/docs/Web, location.toString() can look like that full URL string.
💡
Beginner tip
Prefer location.href when you want a clear property name. Use toString() when you care about the stringifier / coercion behavior—both return the same URL text.
Concept
Understanding the toString() Method
An instance method (stringifier) on WorkerLocation that returns the serialized worker URL as a string.
Returns — a string (full worker URL).
Parameters — none.
Synonym — same result as location.href.
Access — self.location.toString() or location.toString() inside the worker.
Workers only — not available on the main document thread.
Baseline Widely available on MDN (since July 2015).
Foundation
📝 Syntax
Call the method inside a worker script:
JavaScript
toString()
Parameters
None.
Return value
A string containing the serialized URL for the worker’s location (same as WorkerLocation.href).
Typical pattern (MDN idea)
JavaScript
// Inside a Web Worker
const result = self.location.toString();
self.postMessage(result);
Compare
⚖️ toString() vs Related Ideas
Idea
Meaning
location.toString()
Serialized worker URL string
location.href
Same string (documented synonym)
String(location)
May use the stringifier
location.origin
Origin only (no full path)
window.location.toString()
Page URL string (main thread)
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Call toString
self.location.toString()
Return type
String
Same as
self.location.href
Parameters
None
Send to main
self.postMessage(location.toString())
MDN status
Baseline Widely available (since July 2015)
Snapshot
🔍 At a Glance
Four facts to remember about WorkerLocation.toString().
WorkerLocation.toString() 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.toString()
Returns the serialized worker URL as a string. Synonym for location.href 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.toString()Excellent
Bottom line: Call location.toString() inside the worker—or use location.href. Both serialize the worker script URL.
Wrap Up
Conclusion
WorkerLocation.toString() is the stringifier for the worker script URL. It returns the same serialized string as href—call either one inside the worker when you need the full URL text.
Prefer explicit toString() or href over silent coercion in teaching code
Log blob URLs with the full serialized string
❌ Don’t
Expect WorkerLocation on the main thread
Pass arguments to toString()
Assume MDN’s https sample appears in blob demos
Confuse worker URL strings with the page URL
Use only host when you need the full URL (prefer href / toString())
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about WorkerLocation.toString()
The worker script URL, as a string.
5
Core concepts
🔗01
Returns
URL string
API
⚙️02
Workers
self.location
Context
🔒03
No params
toString()
Rule
📄04
= href
same string
Synonym
🎯05
Baseline
since Jul 2015
Status
❓ Frequently Asked Questions
A string containing 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.
Did you know?
Many DOM / URL objects expose a stringifier so "" + location or a template literal can print a useful URL. On WorkerLocation, that stringifier is toString()—and it matches href by design.