WorkerLocation.search returns the search (query) part of the worker’s location as a string. Per MDN, if the worker URL has ?t=67, location.search is "?t=67".
Read the notes below before you rely on this property. Prefer feature detection when support is limited.
Syntax
Use location.search. Start with this line.
JavaScript
self.location.search
Call
What it does
self.location.search
Primary signature.
Built into Web Workers. Read self.location.search (or location.search) inside a worker — no import required.
Library declarations
JavaScript
self.location.search
Parameters
Parameter
Description
Worker context
Required. self.location is a WorkerLocation
Return Value
Return Value
Description
*
String ("?…" or "")
JavaScript Examples
Example 1 — Read location.search
When the worker URL has ?t=67, the property returns that query (MDN idea).
JavaScript
// Worker URL has ?t=67
const result = location.search; // "?t=67"
self.postMessage(result);
No ?… on the URL. The worker script URL has no query.
Empty string.location.search is "", not null.
Add a query.new Worker(url + "?mode=demo") makes search non-empty.
Check clearly. Use search === "" before parsing parameters.
Example 4 — Parse with URLSearchParams
Turn ?t=67 into a named value with get("t").
JavaScript
// Main receives search from the worker, then:
const search = "?t=67";
const params = new URLSearchParams(search);
console.log(params.get("t")); // "67"
Worker has its own URL. Query comes from the Worker script URL.
Page has window.location. That is a different Location object.
Values can differ. Appending ?t=67 to the worker does not change the page URL.
Pick the right one. Inside a worker, always use self.location.search.
Compatibility
Browser Support
WorkerLocation.search 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.search
Supported across modern browsers with Web Workers. Read location.search 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.searchExcellent
Bottom line: Browser / Web Workers only — not a Node.js API. Append ?… to the Worker URL when demos need a non-empty search.
Frequently Asked Questions
A string: the search (query) part of the worker’s location URL—including the leading ? when a query is present. 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 the empty string "" when the worker URL has no query parameters (not null).
Yes. Pass the search string into URLSearchParams—for example new URLSearchParams(location.search)—then use get("key").
No. WorkerLocation.search is read-only. Put the query on the Worker URL when you create the worker.