{"record":{"id":"c8af9cb8c0aee91d","repo":"dotnet/runtime","slug":"missing-window-to-the-query-parameters-from","errorCode":null,"errorMessage":"Missing window to the query parameters from","messagePattern":"Missing window to the query parameters from","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/mono/browser/runtime/loader/run.ts","lineNumber":178,"sourceCode":"        }\n    }\n\n    withMainAssembly (mainAssemblyName: string): DotnetHostBuilder {\n        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, {","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/mono/browser/runtime/loader/run.ts#L160-L196","documentation":"Thrown by withApplicationArgumentsFromQuery in run.ts when globalThis.window is undefined at the time the builder method is called. Reading application arguments from the URL query string requires a browser window object; calling this method from a Web Worker, NodeJS, or a shell environment has no window.location.search to read.","triggerScenarios":"Invoking HostBuilder.withApplicationArgumentsFromQuery() in a non-browser host (worker thread, Node, d8 shell); booting the runtime inside a Service Worker; calling the builder before window is available in an SSR/prerender pass.","commonSituations":"Reusing the same host builder code for browser and Node; running under a JS interpreter that lacks window; prerendering Blazor on the server where window does not exist.","solutions":["Only call withApplicationArgumentsFromQuery in a browser main-thread context; guard with typeof window !== 'undefined'.","For non-browser hosts, use withApplicationArguments(...args) directly.","If you need query args in a worker, read them on the main thread and pass them in."],"exampleFix":"// before: unconditional call\nvar builder = new HostBuilder().withApplicationArgumentsFromQuery();\n// after: guard for browser\nvar builder = new HostBuilder();\nif (typeof globalThis.window !== 'undefined')\n    builder.withApplicationArgumentsFromQuery();","handlingStrategy":"validation","validationCode":"// before calling withApplicationArgumentsFromQuery\nif (typeof globalThis.window === 'undefined')\n    throw new Error('window is required; call this only in a browser main thread');","typeGuard":"function hasWindow(): boolean {\n  return typeof globalThis !== 'undefined' && typeof (globalThis as any).window !== 'undefined';\n}","tryCatchPattern":null,"preventionTips":["Gate withApplicationArgumentsFromQuery behind a window check.","Use withApplicationArguments(...) directly in worker/Node/shell hosts.","Read query args on the main thread and pass them to workers."],"tags":["startup","host-builder","browser","query-args","environment"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}