{"record":{"id":"94eb8775da7ea828","repo":"dotnet/runtime","slug":"urlsearchparams-is-supported","errorCode":null,"errorMessage":"URLSearchParams is supported","messagePattern":"URLSearchParams is supported","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/loader/run.ts","lineNumber":182,"sourceCode":"        try {\n            deep_merge_config(monoConfig, {\n                mainAssemblyName\n            });\n            return this;\n        } catch (err) {\n            mono_exit(1, err);\n            throw err;\n        }\n    }\n\n    withApplicationArgumentsFromQuery (): DotnetHostBuilder {\n        try {\n            if (!globalThis.window) {\n                throw new Error(\"Missing window to the query parameters from\");\n            }\n\n            if (typeof globalThis.URLSearchParams == \"undefined\") {\n                throw new Error(\"URLSearchParams is supported\");\n            }\n\n            const params = new URLSearchParams(globalThis.window.location.search);\n            const values = params.getAll(\"arg\");\n            return this.withApplicationArguments(...values);\n        } catch (err) {\n            mono_exit(1, err);\n            throw err;\n        }\n    }\n\n    withApplicationEnvironment (applicationEnvironment?: string): DotnetHostBuilder {\n        try {\n            deep_merge_config(monoConfig, {\n                applicationEnvironment,\n            });\n            return this;\n        } catch (err) {","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/loader/run.ts#L164-L200","documentation":"Thrown by withApplicationArgumentsFromQuery() when globalThis.URLSearchParams is undefined. Despite the misleading message text ('URLSearchParams is supported'), the guard at line 181 fires when the API is NOT present, preventing the builder from parsing query-string arguments. This is a host-capability check that fails on very old browsers or non-browser JS runtimes that lack URLSearchParams. The .NET WASM loader needs it to read 'arg' query parameters from window.location.search.","triggerScenarios":"Calling dotnet.withApplicationArgumentsFromQuery() in a JS runtime where globalThis.URLSearchParams is undefined (old browser, Node without polyfill, or a non-window worker context). The method also requires globalThis.window to exist.","commonSituations":"Running the .NET WASM runtime in a very old browser (pre-2019), in a Node.js test harness without a URLSearchParams polyfill, or in a service worker / web worker that has no window object. Developers testing locally in Node often hit this.","solutions":["If running in Node or a non-browser environment, avoid withApplicationArgumentsFromQuery() and use withApplicationArguments(...args) to pass args directly.","Polyfill URLSearchParams before creating the runtime: if (typeof globalThis.URLSearchParams === 'undefined') { globalThis.URLSearchParams = require('url').URLSearchParams; }","Upgrade to a modern browser that natively supports URLSearchParams (all evergreen browsers since 2019).","Ensure the code runs in a context that has globalThis.window.location.search available."],"exampleFix":"// before\nconst runtime = await dotnet\n  .withApplicationArgumentsFromQuery()\n  .create();\n\n// after (pass args explicitly instead of relying on URL query string)\nconst runtime = await dotnet\n  .withApplicationArguments('--foo', 'bar')\n  .create();","handlingStrategy":"validation","validationCode":"// Check before calling withApplicationArgumentsFromQuery\nif (typeof globalThis.URLSearchParams === 'undefined' || !globalThis.window) {\n  // use direct args instead\n  dotnet.withApplicationArguments(...myArgs);\n} else {\n  dotnet.withApplicationArgumentsFromQuery();\n}","typeGuard":"function supportsUrlSearchParams(): boolean {\n  return typeof globalThis.URLSearchParams !== 'undefined'\n    && typeof globalThis.window !== 'undefined';\n}","tryCatchPattern":"try {\n  await dotnet.withApplicationArgumentsFromQuery().create();\n} catch (e) {\n  if (e.message.includes('URLSearchParams')) {\n    // fallback: pass args directly\n    await dotnet.withApplicationArguments('--fallback-arg').create();\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always have a fallback path that uses withApplicationArguments() instead of relying on URL query strings.","Polyfill URLSearchParams in non-browser test environments.","Detect the environment (browser vs Node/worker) before choosing the arguments API."],"tags":["environment","browser-support","polyfill","configuration"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}