{"record":{"id":"0ec0e6a08c0aa404","repo":"microsoft/playwright","slug":"output-dir-cannot-point-to-a-system-directory","errorCode":null,"errorMessage":"--output-dir cannot point to a system directory: ${path.resolve(outputDir)}.","messagePattern":"--output-dir cannot point to a system directory: (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/tools/mcp/config.ts","lineNumber":151,"sourceCode":"  let result = defaultConfig;\n  result = mergeConfig(result, resolveConfigPaths(configInFile, configDir));\n  result = mergeConfig(result, resolveConfigPaths(envOverrides, process.cwd()));\n  result = mergeConfig(result, resolveConfigPaths(cliOverrides, process.cwd()));\n\n  const browser = await validateBrowserConfig(result.browser);\n  if (browser.launchOptions.headless === undefined)\n    browser.launchOptions.headless = os.platform() === 'linux' && !process.env.DISPLAY;\n\n  validateOutputDir(result.outputDir);\n\n  return { ...result, browser, configFile };\n}\n\nfunction validateOutputDir(outputDir: string | undefined) {\n  if (!outputDir)\n    return;\n  if (isSystemDirectory(outputDir))\n    throw new Error(`--output-dir cannot point to a system directory: ${path.resolve(outputDir)}.`);\n}\n\nexport async function resolveCLIConfigForCLI(daemonProfilesDir: string, sessionName: string, options: any, env?: NodeJS.ProcessEnv): Promise<FullConfig> {\n  const config = options.config ? path.resolve(options.config) : undefined;\n  try {\n    const defaultConfigFile = path.resolve('.playwright', 'cli.config.json');\n    if (!config && fs.existsSync(defaultConfigFile))\n      options.config = defaultConfigFile;\n  } catch {\n  }\n\n  const daemonOverrides = configFromCLIOptions({\n    endpoint: options.endpoint,\n    cdpEndpoint: options.cdp,\n    config: options.config,\n    browser: options.browser,\n    device: options.device,\n    headless: options.headed ? false : undefined,","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/tools/mcp/config.ts#L133-L169","documentation":"Thrown by `validateOutputDir` (called from both MCP and CLI config resolution) when the resolved `--output-dir` is a system directory (root, Windows system dirs, `/usr`, etc.). Writing artifacts (screenshots, traces, recordings) into a system directory is unsafe, so config validation rejects it.","triggerScenarios":"Setting `--output-dir /`, `--output-dir /usr`, `--output-dir C:\\Windows`, or any path that `isSystemDirectory` flags, in either the MCP server config or the CLI daemon config. The check runs on every config resolution path.","commonSituations":"Defaulting `--output-dir` to an env var that resolves to `/`; passing a bare `/` by mistake; a misconfigured config file whose `outputDir` points at a system path; relative paths that resolve unexpectedly to a system dir from an odd cwd.","solutions":["Point `--output-dir` at a writable, non-system directory (e.g. `./test-results`, `~/artifacts`).","If the value comes from an env var, set it to a concrete project-relative path.","Verify the resolved absolute path (shown in the error) is what you intended."],"exampleFix":"# before\n--output-dir /\n# after\n--output-dir ./test-results","handlingStrategy":"validation","validationCode":"import { isSystemDirectory } from '@utils/fileUtils';\nfunction assertOutputDir(dir: string | undefined) {\n  if (dir && isSystemDirectory(dir))\n    throw new Error(`output-dir is a system directory: ${dir}; choose a project path.`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a project-relative, writable directory for --output-dir.","Sanitize env-var-driven paths before passing them as output-dir.","Confirm the resolved absolute path is intended before launch."],"tags":["config","output-dir","validation","filesystem","safety"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}