dotnet/runtime · error · Error

Missing window to the query parameters from

Error message

Missing window to the query parameters from

What it means

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.

Solutions

  1. Only call withApplicationArgumentsFromQuery in a browser context; guard with if (typeof window !== 'undefined').
  2. In Node, pass args explicitly via withApplicationArguments(...args).
  3. In a worker, read location.search if available or pipe args via postMessage then withApplicationArguments.
  4. Refactor so the builder configuration is environment-agnostic.

Example fix

// before
builder.withApplicationArgumentsFromQuery();

// after
if (typeof globalThis.window !== 'undefined') {
  builder.withApplicationArgumentsFromQuery();
} else {
  builder.withApplicationArguments(process.argv.slice(2));
}
Defensive patterns

Strategy: type-guard

Validate before calling

function hasWindow(): boolean {
  return typeof globalThis !== 'undefined' && typeof (globalThis as any).window !== 'undefined';
}
if (hasWindow()) builder.withApplicationArgumentsFromQuery();

Type guard

function isBrowserEnv(): boolean {
  return typeof (globalThis as any).window === 'object' && typeof (globalThis as any).document === 'object';
}

Try / catch

try { builder.withApplicationArgumentsFromQuery(); } catch (e) {
  if (/Missing window/.test((e as Error).message)) {
    builder.withApplicationArguments(process.argv.slice(2));
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dotnet/runtime@60108ba66e (2026-08-10). Data as JSON: /api/errors/efc6b5bb160c6b38. Report an issue: GitHub.

Appendix: source

Thrown at src/native/libs/Common/JavaScript/loader/host-builder.ts:71

            diagnosticTracing: enabled
        });
        return this;
    }
    withDebugging(level: number): DotnetHostBuilder {
        mergeLoaderConfig({
            debugLevel: level
        });
        return this;
    }
    withMainAssembly(mainAssemblyName: string): DotnetHostBuilder {
        mergeLoaderConfig({
            mainAssemblyName: mainAssemblyName
        });
        return this;
    }
    withApplicationArgumentsFromQuery(): DotnetHostBuilder {
        if (!globalThis.window) {
            throw new Error("Missing window to the query parameters from");
        }

        if (typeof globalThis.URLSearchParams === "undefined") {
            throw new Error("URLSearchParams is supported");
        }

        const params = new URLSearchParams(globalThis.window.location.search);
        const values = params.getAll("arg");
        return this.withApplicationArguments(...values);
    }
    withApplicationEnvironment(applicationEnvironment?: string): DotnetHostBuilder {
        mergeLoaderConfig({
            applicationEnvironment: applicationEnvironment
        });
        return this;
    }
    withApplicationCulture(applicationCulture?: string): DotnetHostBuilder {
        mergeLoaderConfig({

View on GitHub (pinned to 60108ba66e)