The search property of a WorkerLocation object returns the search (query string) of the worker’s location. Learn self.location.search, the leading ?, how it differs from hash and href, and how to demo it with blob worker URLs—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
A search (query string) is the part of a URL that starts with ?—for example ?t=67 in https://example.com/path?t=67. Inside a worker, self.location.search returns that query for the worker script URL.
MDN’s classic idea: on a worker related to a URL with ?t=67, location.search can look like "?t=67".
💡
Beginner tip
No query means search is often "" (empty). The fragment after # is hash, not search.
Concept
Understanding the search Property
A read-only instance property on WorkerLocation that returns the worker’s query string as a string.
Value — a string (e.g. "?t=67" or "").
vs hash — search is ?…; hash is #….
Access — self.location.search or location.search 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 = self.location.search;
// e.g. "?t=67"
Value
A string.
Typical pattern (MDN idea)
JavaScript
// Inside a Web Worker
const result = self.location.search;
self.postMessage(result);
Demo tip: append a query to a blob worker URL
JavaScript
const base = URL.createObjectURL(new Blob(
["self.postMessage(location.search);"],
{ type: "application/javascript" }
));
const worker = new Worker(base + "?t=67");
Compare
⚖️ search vs Related Ideas
Idea
Meaning
location.search
Query string (?… or "")
location.hash
Fragment (#… or "")
location.pathname
Path only (no query)
location.href
Full serialized worker URL
URLSearchParams
Parse key/value pairs from search
window.location.search
Query of the page (main thread)
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Read search
self.location.search
Return type
String
MDN example shape
"?t=67"
No query
Often ""
Send to main
self.postMessage(location.search)
MDN status
Baseline Widely available (since July 2015)
Snapshot
🔍 At a Glance
Four facts to remember about WorkerLocation.search.
Returns
search
String
Where
in worker
self.location
Writable
no
Read-only
Baseline
widely
Since Jul 2015
Hands-On
Examples Gallery
Examples follow MDN WorkerLocation.search. Labs append ?… to blob worker URLs so you can see a real query string.
📚 Getting Started
Read the search string the MDN way.
Example 1 — Read self.location.search (MDN Idea)
Create a worker with ?t=67 and post the search string.
JavaScript
const result = self.location.search;
// e.g. "?t=67"
self.postMessage(result);
WorkerLocation.search 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.search
Returns the worker's query string. Read it with self.location.search 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.searchExcellent
Bottom line: Read location.search inside the worker—empty means no query. Pair with hash and URLSearchParams when needed.
Wrap Up
Conclusion
WorkerLocation.search is the worker-side query string for the script URL. Read it inside the worker, expect an empty string when there is no query, and use URLSearchParams when you need named parameters.
Keep search and hash separate in your mental model
Use postMessage to surface the value on the page
❌ Don’t
Expect WorkerLocation on the main thread
Assign to location.search in a worker (read-only)
Confuse ? query with # hash
Assume every worker URL has a non-empty search
Forget the leading ? when comparing sample strings
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about WorkerLocation.search
The worker script’s query string.
5
Core concepts
🔗01
Returns
?query string
API
⚙️02
Workers
self.location
Context
🔒03
Read-only
no assign
Rule
📄04
vs hash
? vs #
Compare
🎯05
Baseline
since Jul 2015
Status
❓ Frequently Asked Questions
A string: the search (query) part of the worker's location. When present it usually starts with "?". Access it inside a worker as self.location.search or location.search.
No. MDN marks WorkerLocation.search as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is only available in Web Workers.
search is the query string (starts with ? when present). hash is the fragment (starts with # when present). They are separate parts of the URL.
location.search is often the empty string "" when the worker URL has no query parameters.
Yes. On the main thread (or in modern workers), you can pass the search string into URLSearchParams—for example new URLSearchParams(location.search).
No. WorkerLocation.search is read-only.
Did you know?
MDN’s example returns ?t=67 including the question mark. You can append the same kind of query to a blob worker URL (new Worker(blobUrl + "?t=67")—just like these try-it labs.