{"record":{"id":"efc6b5bb160c6b38","repo":"dotnet/runtime","slug":"missing-window-to-the-query-parameters-from-efc6b5","errorCode":null,"errorMessage":"Missing window to the query parameters from","messagePattern":"Missing window to the query parameters from","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/native/libs/Common/JavaScript/loader/host-builder.ts","lineNumber":71,"sourceCode":"            diagnosticTracing: enabled\n        });\n        return this;\n    }\n    withDebugging(level: number): DotnetHostBuilder {\n        mergeLoaderConfig({\n            debugLevel: level\n        });\n        return this;\n    }\n    withMainAssembly(mainAssemblyName: string): DotnetHostBuilder {\n        mergeLoaderConfig({\n            mainAssemblyName: mainAssemblyName\n        });\n        return this;\n    }\n    withApplicationArgumentsFromQuery(): DotnetHostBuilder {\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    }\n    withApplicationEnvironment(applicationEnvironment?: string): DotnetHostBuilder {\n        mergeLoaderConfig({\n            applicationEnvironment: applicationEnvironment\n        });\n        return this;\n    }\n    withApplicationCulture(applicationCulture?: string): DotnetHostBuilder {\n        mergeLoaderConfig({","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/native/libs/Common/JavaScript/loader/host-builder.ts#L53-L89","documentation":"withApplicationArgumentsFromQuery() on HostBuilder requires globalThis.window (i.e. a browser) because it reads location.search. If window is undefined (Node.js, shell, worker without window) it throws this. The message itself is awkwardly worded ('Missing window to the query parameters from').","triggerScenarios":"Calling dotnet.withApplicationArgumentsFromQuery() in a non-browser host: Node.js, a Web Worker without DOM, or the JS shell. The guard fires before any URL parsing.","commonSituations":"Reusing the same bootstrap code in Node and browser; running Blazor/.NET-wasm tests under Node; SSR/prerendering harness invoking the loader; migrating from browser to worker without removing the call.","solutions":["Only call withApplicationArgumentsFromQuery() in a browser environment; gate it on typeof globalThis.window !== 'undefined'.","In Node/shell, pass arguments explicitly via withApplicationArguments(...args) instead.","Move the call behind an environment check (ENVIRONMENT_IS_WEB) in your bootstrap."],"exampleFix":"// before\nbuilder.withApplicationArgumentsFromQuery();\n\n// after\nif (typeof globalThis.window !== 'undefined') {\n  builder.withApplicationArgumentsFromQuery();\n} else {\n  builder.withApplicationArguments('--arg1', '--arg2');\n}","handlingStrategy":"type-guard","validationCode":"if (typeof globalThis.window === 'undefined') {\n  throw new Error('withApplicationArgumentsFromQuery() requires a browser — pass args via withApplicationArguments()');\n}","typeGuard":"function isBrowserWithWindow(g: any): g is { window: Window } {\n  return typeof g?.window !== 'undefined';\n}","tryCatchPattern":null,"preventionTips":["Gate browser-only calls behind ENVIRONMENT_IS_WEB or a window check.","Keep a single bootstrap entry point per environment.","Write a unit test that boots under Node to catch environment mismatches early."],"tags":["environment","browser","node","arguments","config"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}