microsoft/playwright · error · Error

Init script file does not exist: ${script}

Error message

Init script file does not exist: ${script}

What it means

Thrown by validateBrowserConfig() in the MCP config layer when an entry in the browser.initScript array does not resolve to an existing file on disk. Each path is checked with fileExistsAsync before the browser is launched, so a bad path aborts startup rather than producing a silent failure inside the page. The error exists because init scripts are injected into every new page and a missing one would otherwise yield an empty/non-functional injection.

Source

Thrown at packages/playwright-core/src/tools/mcp/config.ts:240

    // Assign channel only if the browserName is not provided, otherwise assume full control to the user.
    if (browser.launchOptions.channel === undefined)
      browser.launchOptions.channel = 'chrome';
  }

  if (browserName === 'chromium' && browser.launchOptions.chromiumSandbox === undefined) {
    if (process.platform === 'linux')
      browser.launchOptions.chromiumSandbox = browser.launchOptions.channel !== 'chromium' && browser.launchOptions.channel !== 'chrome-for-testing';
    else
      browser.launchOptions.chromiumSandbox = true;
  }

  if (browser.isolated && browser.userDataDir)
    throw new Error('Browser userDataDir is not supported in isolated mode.');

  if (browser.initScript) {
    for (const script of browser.initScript) {
      if (!await fileExistsAsync(script))
        throw new Error(`Init script file does not exist: ${script}`);
    }
  }
  if (browser.initPage) {
    for (const page of browser.initPage) {
      if (!await fileExistsAsync(page))
        throw new Error(`Init page file does not exist: ${page}`);
    }
  }
  if (browser.contextOptions.viewport === undefined) {
    if (browser.launchOptions.headless)
      browser.contextOptions.viewport = { width: 1280, height: 720 };
    else
      browser.contextOptions.viewport = null;
  }

  if (browserName === 'chromium') {
    browser.launchOptions.args = browser.launchOptions.args ?? [];
    if (!browser.launchOptions.args.some(a => a.includes('--disable-blink-features')))

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. Verify the exact path with ls or test -f against the value printed in the error message, using the same cwd the MCP server runs from.
  2. Use an absolute path (e.g. /home/user/scripts/init.js) instead of a relative or tilde path to remove cwd ambiguity.
  3. If the path is correct in your shell but wrong in the process, check whether the MCP server is launched from a different working directory and pass an absolute path.
  4. Confirm the file is readable by the user running the MCP server (permissions, not just existence).

Example fix

// before (relative, wrong cwd)
--init-script ./scripts/init.js
// after (absolute)
--init-script /home/user/project/scripts/init.js
Defensive patterns

Strategy: validation

Validate before calling

import fs from 'fs';
const ok = initScriptPaths.every(p => fs.existsSync(p));
if (!ok) {
  const missing = initScriptPaths.filter(p => !fs.existsSync(p));
  throw new Error(`Missing init scripts: ${missing.join(', ')}`);
}

Type guard

function isExistingFile(p: string): boolean {
  try { return fs.statSync(p).isFile(); } catch { return false; }
}

Prevention

When it happens

Trigger: Passing --init-script /path/missing.js on the Playwright MCP CLI, or setting browser.initScript in a config file to a path that does not exist. Also triggered by a relative path that resolves against an unexpected cwd, or by a tilde (~) that is not expanded.

Common situations: Typo in the script path; script lives outside the project root and a relative path is used; path copied from another machine where the file layout differs; CI running from a different working directory than local.

Related errors


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