{"record":{"id":"380395b06ebff6d6","repo":"microsoft/playwright","slug":"cannot-find-trace-file","errorCode":null,"errorMessage":"Cannot find .trace file","messagePattern":"Cannot find \\.trace file","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/isomorphic/trace/traceLoader.ts","lineNumber":55,"sourceCode":"\n  constructor() {\n  }\n\n  async load(backend: TraceLoaderBackend, traceFile?: string, unzipProgress?: (done: number, total: number) => void) {\n    this._backend = backend;\n\n    const prefix = traceFile?.match(/(.+)\\.trace$/)?.[1];\n    const prefixes: string[] = [];\n    let hasSource = false;\n    for (const entryName of await this._backend.entryNames()) {\n      const match = entryName.match(/(.+)\\.trace$/);\n      if (match && (!prefix || prefix  === match[1]))\n        prefixes.push(match[1] || '');\n      if (entryName.startsWith('src/') || entryName.includes('src@'))\n        hasSource = true;\n    }\n    if (!prefixes.length)\n      throw new Error('Cannot find .trace file');\n\n    this._snapshotStorage = new SnapshotStorage();\n\n    // 3 * ordinals progress increments below.\n    const total = prefixes.length * 3;\n    let done = 0;\n    for (const prefix of prefixes) {\n      const contextEntry = createEmptyContext();\n      contextEntry.hasSource = hasSource;\n      const modernizer = new TraceModernizer(contextEntry, this._snapshotStorage);\n\n      const trace = await this._backend.readText(prefix + '.trace') || '';\n      modernizer.appendTrace(trace);\n      unzipProgress?.(++done, total);\n\n      const network = await this._backend.readText(prefix + '.network') || '';\n      modernizer.appendTrace(network);\n      unzipProgress?.(++done, total);","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/isomorphic/trace/traceLoader.ts#L37-L73","documentation":"Thrown by TraceLoader.load when the loaded trace archive (or backend entry list) contains no entries whose name matches `*.trace`. The loader scans backend.entryNames() for a regex match and, finding none, cannot proceed because there is no trace event stream to modernize.","triggerScenarios":"Opening a non-trace file (e.g. a .zip with unrelated content), a corrupted/partial trace archive, a trace exported without the `.trace` resource, or pointing the trace viewer at a directory backend whose entries lack the `.trace` suffix.","commonSituations":"Passing the wrong file to `npx playwright show-trace`; an interrupted trace write that never flushed the `.trace` entry; a custom TraceLoaderBackend returning unexpected entry names; bundling a `.trace` inside another archive format.","solutions":["Verify the file is a valid Playwright trace (re-export via `--trace on`).","Confirm the trace path is correct and the file is not empty/corrupted.","If using a custom backend, ensure entryNames() returns names ending in `.trace`.","Re-record the trace to rule out capture failure."],"exampleFix":"// before\ntraceLoader.load(backend, 'maybe-a-screenshot.png');\n\n// after\nconst tracePath = 'trace.zip';\nif (!tracePath.endsWith('.zip') && !tracePath.endsWith('.trace'))\n  throw new Error(`Expected a .zip/.trace file, got ${tracePath}`);\ntraceLoader.load(backend, tracePath);","handlingStrategy":"validation","validationCode":"async function ensureTraceEntry(backend: TraceLoaderBackend) {\n  const names = await backend.entryNames();\n  if (!names.some(n => n.endsWith('.trace')))\n    throw new Error('Selected archive has no .trace entry; re-record with --trace on');\n}","typeGuard":"async function archiveHasTrace(backend: TraceLoaderBackend): Promise<boolean> {\n  return (await backend.entryNames()).some(n => n.endsWith('.trace'));\n}","tryCatchPattern":"try {\n  await traceLoader.load(backend, file);\n} catch (e) {\n  if (/Cannot find \\.trace file/.test(e.message)) {\n    console.error(`${file} is not a valid Playwright trace. Re-record with --trace on.`);\n    process.exit(2);\n  }\n  throw e;\n}","preventionTips":["Always record with `--trace on` (or trace: 'on') to guarantee the .trace entry exists.","Verify trace files by extension and non-zero size before loading.","Keep the trace export path stable across record and inspect steps."],"tags":["trace","viewer","file-io","validation"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}