microsoft/playwright · error · Error

Trace file ${traceFileOrUrl} does not exist!

Error message

Trace file ${traceFileOrUrl} does not exist!

What it means

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.

Source

Thrown at packages/playwright-core/src/server/trace/viewer/traceViewer.ts:86

  if (!traceFileOrUrl)
    return traceFileOrUrl;

  if (traceFileOrUrl.startsWith('http://') || traceFileOrUrl.startsWith('https://'))
    return traceFileOrUrl;

  let traceFile = traceFileOrUrl;
  // If .json is requested, we'll synthesize it.
  if (traceFile.endsWith('.json'))
    return toFilePathUrl(traceFile);

  try {
    const stat = fs.statSync(traceFile);
    // If the path is a directory, add 'trace.dir' which has a special handler.
    if (stat.isDirectory())
      traceFile = path.join(traceFile, tracesDirMarker);
    return toFilePathUrl(traceFile);
  } catch {
    throw new Error(`Trace file ${traceFileOrUrl} does not exist!`);
  }
}

export async function startTraceViewerServer(options: TraceViewerServerOptions & { allowedFileRoots: () => string[] }): Promise<HttpServer> {
  const server = new HttpServer(libPath('vite', 'traceViewer'));
  const isAllowed = (filePath: string) => options.allowedFileRoots().some(root => isPathInside(path.resolve(root), filePath));

  const serveTraceDataRoute = (request: http.IncomingMessage, response: http.ServerResponse, relativePath: string): boolean => {
    if (!relativePath.startsWith('/file'))
      return false;
    const url = new URL('http://localhost' + request.url!);
    try {
      const filePath = path.resolve(url.searchParams.get('path')!);
      if (!isAllowed(filePath)) {
        response.statusCode = 403;
        response.end();
        return true;
      }

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. Verify the path exists with fs.existsSync before launching the viewer.
  2. Use an absolute path to the trace file or trace directory.
  3. If pointing at a directory, make sure it contains the produced trace files (run the test with trace enabled).

Example fix

// before
const { spawnSync } = require('child_process');
spawnSync('npx', ['playwright', 'show-trace', maybePath]);

// after
const fs = require('fs');
if (fs.existsSync(maybePath)) {
  spawnSync('npx', ['playwright', 'show-trace', path.resolve(maybePath)]);
} else {
  console.error(`Trace not found: ${maybePath}`);
}
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
function assertTraceExists(p) {
  if (!p || (!p.startsWith('http://') && !p.startsWith('https://') && !fs.existsSync(p)))
    throw new Error(`Trace file not found: ${p}`);
}
assertTraceExists(process.argv[2]);

Try / catch

const { spawnSync } = require('child_process');
const fs = require('fs');
if (!fs.existsSync(tracePath)) {
  console.error(`Trace not found: ${tracePath}`);
} else {
  spawnSync('npx', ['playwright', 'show-trace', tracePath], { stdio: 'inherit' });
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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