dotnet/runtime · error · Error

Missing window to the query parameters from

Error message

Missing window to the query parameters from

What it means

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.

Solutions

  1. Only call withApplicationArgumentsFromQuery in a browser main-thread context; guard with typeof window !== 'undefined'.
  2. For non-browser hosts, use withApplicationArguments(...args) directly.
  3. If you need query args in a worker, read them on the main thread and pass them in.

Example fix

// before: unconditional call
var builder = new HostBuilder().withApplicationArgumentsFromQuery();
// after: guard for browser
var builder = new HostBuilder();
if (typeof globalThis.window !== 'undefined')
    builder.withApplicationArgumentsFromQuery();
Defensive patterns

Strategy: validation

Validate before calling

// before calling withApplicationArgumentsFromQuery
if (typeof globalThis.window === 'undefined')
    throw new Error('window is required; call this only in a browser main thread');

Type guard

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

Prevention

When it happens

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

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

Related errors


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

Appendix: source

Thrown at src/mono/browser/runtime/loader/run.ts:178

        }
    }

    withMainAssembly (mainAssemblyName: string): DotnetHostBuilder {
        try {
            deep_merge_config(monoConfig, {
                mainAssemblyName
            });
            return this;
        } catch (err) {
            mono_exit(1, err);
            throw err;
        }
    }

    withApplicationArgumentsFromQuery (): DotnetHostBuilder {
        try {
            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);
        } catch (err) {
            mono_exit(1, err);
            throw err;
        }
    }

    withApplicationEnvironment (applicationEnvironment?: string): DotnetHostBuilder {
        try {
            deep_merge_config(monoConfig, {

View on GitHub (pinned to 60108ba66e)