{"record":{"id":"53f4c539725f64ff","repo":"microsoft/playwright","slug":"init-script-file-does-not-exist-script","errorCode":null,"errorMessage":"Init script file does not exist: ${script}","messagePattern":"Init script file does not exist: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/tools/mcp/config.ts","lineNumber":240,"sourceCode":"    // Assign channel only if the browserName is not provided, otherwise assume full control to the user.\n    if (browser.launchOptions.channel === undefined)\n      browser.launchOptions.channel = 'chrome';\n  }\n\n  if (browserName === 'chromium' && browser.launchOptions.chromiumSandbox === undefined) {\n    if (process.platform === 'linux')\n      browser.launchOptions.chromiumSandbox = browser.launchOptions.channel !== 'chromium' && browser.launchOptions.channel !== 'chrome-for-testing';\n    else\n      browser.launchOptions.chromiumSandbox = true;\n  }\n\n  if (browser.isolated && browser.userDataDir)\n    throw new Error('Browser userDataDir is not supported in isolated mode.');\n\n  if (browser.initScript) {\n    for (const script of browser.initScript) {\n      if (!await fileExistsAsync(script))\n        throw new Error(`Init script file does not exist: ${script}`);\n    }\n  }\n  if (browser.initPage) {\n    for (const page of browser.initPage) {\n      if (!await fileExistsAsync(page))\n        throw new Error(`Init page file does not exist: ${page}`);\n    }\n  }\n  if (browser.contextOptions.viewport === undefined) {\n    if (browser.launchOptions.headless)\n      browser.contextOptions.viewport = { width: 1280, height: 720 };\n    else\n      browser.contextOptions.viewport = null;\n  }\n\n  if (browserName === 'chromium') {\n    browser.launchOptions.args = browser.launchOptions.args ?? [];\n    if (!browser.launchOptions.args.some(a => a.includes('--disable-blink-features')))","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/tools/mcp/config.ts#L222-L258","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Use an absolute path (e.g. /home/user/scripts/init.js) instead of a relative or tilde path to remove cwd ambiguity.","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.","Confirm the file is readable by the user running the MCP server (permissions, not just existence)."],"exampleFix":"// before (relative, wrong cwd)\n--init-script ./scripts/init.js\n// after (absolute)\n--init-script /home/user/project/scripts/init.js","handlingStrategy":"validation","validationCode":"import fs from 'fs';\nconst ok = initScriptPaths.every(p => fs.existsSync(p));\nif (!ok) {\n  const missing = initScriptPaths.filter(p => !fs.existsSync(p));\n  throw new Error(`Missing init scripts: ${missing.join(', ')}`);\n}","typeGuard":"function isExistingFile(p: string): boolean {\n  try { return fs.statSync(p).isFile(); } catch { return false; }\n}","tryCatchPattern":null,"preventionTips":["Resolve init-script paths to absolute paths (path.resolve) before passing them to the CLI.","Add a startup assertion that all configured init-script files exist.","Keep init scripts inside the project tree so relative paths are stable across machines."],"tags":["mcp","config","filesystem","init-script","validation"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}