{"record":{"id":"8e6653c001126cb9","repo":"microsoft/playwright","slug":"trace-file-tracefileorurl-does-not-exist","errorCode":null,"errorMessage":"Trace file ${traceFileOrUrl} does not exist!","messagePattern":"Trace file (.+?) does not exist!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/server/trace/viewer/traceViewer.ts","lineNumber":86,"sourceCode":"  if (!traceFileOrUrl)\n    return traceFileOrUrl;\n\n  if (traceFileOrUrl.startsWith('http://') || traceFileOrUrl.startsWith('https://'))\n    return traceFileOrUrl;\n\n  let traceFile = traceFileOrUrl;\n  // If .json is requested, we'll synthesize it.\n  if (traceFile.endsWith('.json'))\n    return toFilePathUrl(traceFile);\n\n  try {\n    const stat = fs.statSync(traceFile);\n    // If the path is a directory, add 'trace.dir' which has a special handler.\n    if (stat.isDirectory())\n      traceFile = path.join(traceFile, tracesDirMarker);\n    return toFilePathUrl(traceFile);\n  } catch {\n    throw new Error(`Trace file ${traceFileOrUrl} does not exist!`);\n  }\n}\n\nexport async function startTraceViewerServer(options: TraceViewerServerOptions & { allowedFileRoots: () => string[] }): Promise<HttpServer> {\n  const server = new HttpServer(libPath('vite', 'traceViewer'));\n  const isAllowed = (filePath: string) => options.allowedFileRoots().some(root => isPathInside(path.resolve(root), filePath));\n\n  const serveTraceDataRoute = (request: http.IncomingMessage, response: http.ServerResponse, relativePath: string): boolean => {\n    if (!relativePath.startsWith('/file'))\n      return false;\n    const url = new URL('http://localhost' + request.url!);\n    try {\n      const filePath = path.resolve(url.searchParams.get('path')!);\n      if (!isAllowed(filePath)) {\n        response.statusCode = 403;\n        response.end();\n        return true;\n      }","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/server/trace/viewer/traceViewer.ts#L68-L104","documentation":"The trace viewer's URL/path validator throws when the supplied trace path does not exist on the filesystem (fs.statSync throws inside the try). It is hit when opening a local trace file or directory that has been moved, deleted, or never written. HTTP(S) URLs and .json paths bypass the stat check.","triggerScenarios":"Running `npx playwright show-trace <path>` where <path> does not exist; pointing the trace viewer at an output directory from a different machine/CI run; a typo in the path; the trace was written to a temp dir that got cleaned.","commonSituations":"CI artefact paths that differ locally; relative paths resolved from the wrong cwd; passing a .zip before it was produced (test failed before stopChunk); stale references to deleted trace dirs.","solutions":["Verify the path exists with fs.existsSync before launching the viewer.","Use an absolute path to the trace file or trace directory.","If pointing at a directory, make sure it contains the produced trace files (run the test with trace enabled)."],"exampleFix":"// before\nconst { spawnSync } = require('child_process');\nspawnSync('npx', ['playwright', 'show-trace', maybePath]);\n\n// after\nconst fs = require('fs');\nif (fs.existsSync(maybePath)) {\n  spawnSync('npx', ['playwright', 'show-trace', path.resolve(maybePath)]);\n} else {\n  console.error(`Trace not found: ${maybePath}`);\n}","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction assertTraceExists(p) {\n  if (!p || (!p.startsWith('http://') && !p.startsWith('https://') && !fs.existsSync(p)))\n    throw new Error(`Trace file not found: ${p}`);\n}\nassertTraceExists(process.argv[2]);","typeGuard":null,"tryCatchPattern":"const { spawnSync } = require('child_process');\nconst fs = require('fs');\nif (!fs.existsSync(tracePath)) {\n  console.error(`Trace not found: ${tracePath}`);\n} else {\n  spawnSync('npx', ['playwright', 'show-trace', tracePath], { stdio: 'inherit' });\n}","preventionTips":["Pass absolute paths to show-trace.","Confirm the trace artefact exists after the test run before opening.","Keep trace output dirs outside OS temp so they aren't auto-cleaned."],"tags":["trace-viewer","filesystem","cli"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}