{"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":"exception","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/60108ba66eb7d1d12f595480091b4ad80a24b172/src/native/libs/Common/JavaScript/loader/host-builder.ts#L53-L89","documentation":"withApplicationArgumentsFromQuery() requires a browser window to read location.search. Thrown when globalThis.window is falsy, i.e. running under Node, a Web Worker without window, or a non-browser shell. The method parses ?arg=... query parameters and forwards them as application arguments.","triggerScenarios":"Calling builder.withApplicationArgumentsFromQuery() in a Node script that imports the loader. Calling it inside a service worker or worker that lacks window. SSR/prerendering pass that runs the same module server-side.","commonSituations":"Unit testing the loader under jsdom where window exists but is the wrong shape (jsdom has window, so this would NOT fire; the trigger is true absence of window). Reusing bootstrap code in a Node-side prerender. Worker context imports.","solutions":["Only call withApplicationArgumentsFromQuery in a browser context; guard with if (typeof window !== 'undefined').","In Node, pass args explicitly via withApplicationArguments(...args).","In a worker, read location.search if available or pipe args via postMessage then withApplicationArguments.","Refactor so the builder configuration is environment-agnostic."],"exampleFix":"// before\nbuilder.withApplicationArgumentsFromQuery();\n\n// after\nif (typeof globalThis.window !== 'undefined') {\n  builder.withApplicationArgumentsFromQuery();\n} else {\n  builder.withApplicationArguments(process.argv.slice(2));\n}","handlingStrategy":"type-guard","validationCode":"function hasWindow(): boolean {\n  return typeof globalThis !== 'undefined' && typeof (globalThis as any).window !== 'undefined';\n}\nif (hasWindow()) builder.withApplicationArgumentsFromQuery();","typeGuard":"function isBrowserEnv(): boolean {\n  return typeof (globalThis as any).window === 'object' && typeof (globalThis as any).document === 'object';\n}","tryCatchPattern":"try { builder.withApplicationArgumentsFromQuery(); } catch (e) {\n  if (/Missing window/.test((e as Error).message)) {\n    builder.withApplicationArguments(process.argv.slice(2));\n  } else throw e;\n}","preventionTips":["Detect environment once at module load (ENVIRONMENT_IS_NODE / ENVIRONMENT_IS_WEB) and branch accordingly.","In Node, prefer withApplicationArguments(...process.argv.slice(2)).","In SSR/prerender, skip the query-parameter step entirely.","Centralize bootstrap so environment detection lives in one place."],"tags":["environment","node","browser","arguments"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}