microsoft/playwright · error · Error

Arguments can not specify page to be opened

Error message

Arguments can not specify page to be opened

What it means

WebKit's defaultArgs rejects any launch argument that does not start with '-' (i.e. a positional argument). WebKit treats the first positional argument as a URL/file to open at startup, which conflicts with Playwright's own page management and would open an uncontrolled page. Only flag-style arguments (--flag or -flag) are permitted.

Source

Thrown at packages/playwright-core/src/server/webkit/webkit.ts:107

  override doRewriteStartupLog(logs: string): string {
    if (logs.includes('Failed to open display') || logs.includes('cannot open display'))
      logs = '\n' + wrapInASCIIBox(kNoXServerRunningError, 1);
    return logs;
  }

  override attemptToGracefullyCloseBrowser(transport: ConnectionTransport): void {
    // Note that it's fine to reuse the transport, since our connection ignores kBrowserCloseMessageId.
    transport.send({ method: 'Playwright.close', params: {}, id: kBrowserCloseMessageId });
  }

  override async defaultArgs(options: types.LaunchOptions, isPersistent: boolean, userDataDir: string): Promise<string[]> {
    const { args = [], headless } = options;
    const userDataDirArg = args.find(arg => arg.startsWith('--user-data-dir'));
    if (userDataDirArg)
      throw this._createUserDataDirArgMisuseError('--user-data-dir');
    if (args.find(arg => !arg.startsWith('-')))
      throw new Error('Arguments can not specify page to be opened');
    const isWSL = options.channel === 'webkit-wsl';
    const webkitArguments = [isWSL ? '--remote-debugging-port=0' : '--inspector-pipe'];

    if (isWSL) {
      const wslExecutablePath = options.executablePath || registry.findExecutable('webkit-wsl')!.wslExecutablePath!;
      webkitArguments.unshift(
          '-d', kWSLDistribution,
          '-u', kWSLUser,
          '--cd', kWSLHome,
          '--',
          wslExecutablePath,
      );
    }

    if (process.platform === 'win32' && !isWSL)
      webkitArguments.push('--disable-accelerated-compositing');
    if (headless)
      webkitArguments.push('--headless');

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. Remove the positional URL/path from args.
  2. Open the page after launch with await page.goto(url).
  3. If you need to pass a file, use the appropriate --flag (e.g. --user-data-dir, which itself has a separate guard).

Example fix

// before
const b = await webkit.launch({ args: ['https://example.com'] });

// after
const b = await webkit.launch({ args: ['--disable-hardware-overlays'] });
const p = await b.newPage();
await p.goto('https://example.com');
Defensive patterns

Strategy: validation

Validate before calling

function sanitizeArgs(args) {
  const bad = (args || []).find(a => !String(a).startsWith('-'));
  if (bad) throw new Error(`WebKit launch args must be flags; got positional: ${bad}`);
}
sanitizeArgs(launchOptions.args);

Prevention

When it happens

Trigger: Passing a URL or file path as a positional item in launch({ args: [...] }) for a webkit launch, e.g. args: ['https://example.com'] or args: ['/path/to/file']. Any arg not starting with '-' triggers it.

Common situations: Copy-pasting chromium launch args (which historically tolerated a URL) into a webkit launch; trying to open a startup page via args instead of page.goto; passing a profile/data file as a positional arg.

Related errors


AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12). Data as JSON: /api/errors/f2279e46991c6b79. Report an issue: GitHub.