{"record":{"id":"2224873a8da1bfd8","repo":"microsoft/playwright","slug":"no-trace-opened-run-npx-playwright-trace-open-f","errorCode":null,"errorMessage":"No trace opened. Run 'npx playwright trace open <file>' first.","messagePattern":"No trace opened\\. Run 'npx playwright trace open <file>' first\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/tools/trace/traceUtils.ts","lineNumber":57,"sourceCode":"    this.loader = loader;\n    this.ordinalToCallId = ordinals.ordinalToCallId;\n    this.callIdToOrdinal = ordinals.callIdToOrdinal;\n  }\n\n  resolveActionId(actionId: string): ActionEntry | undefined {\n    const ordinal = parseInt(actionId, 10);\n    if (!isNaN(ordinal)) {\n      const callId = this.ordinalToCallId.get(ordinal);\n      if (callId)\n        return this.model.actions.find(a => a.callId === callId);\n    }\n    return this.model.actions.find(a => a.callId === actionId);\n  }\n}\n\nfunction ensureTraceOpen(): string {\n  if (!fs.existsSync(traceDir))\n    throw new Error(`No trace opened. Run 'npx playwright trace open <file>' first.`);\n  return traceDir;\n}\n\nexport async function closeTrace() {\n  if (fs.existsSync(traceDir))\n    await fs.promises.rm(traceDir, { recursive: true });\n}\n\nexport async function openTrace(traceFile: string) {\n  const filePath = path.resolve(traceFile);\n  if (!fs.existsSync(filePath))\n    throw new Error(`Trace file not found: ${filePath}`);\n  await closeTrace();\n  await fs.promises.mkdir(traceDir, { recursive: true });\n  if (filePath.endsWith('.zip'))\n    await extractTrace(filePath, traceDir);\n  else\n    await fs.promises.writeFile(path.join(traceDir, '.link'), filePath, 'utf-8');","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/tools/trace/traceUtils.ts#L39-L75","documentation":"Thrown by ensureTraceOpen() when the .playwright-cli/trace directory does not exist. This directory is created by openTrace(); other trace sub-commands (snapshot, etc.) call loadTrace() which calls ensureTraceOpen(), so they require a trace to have been opened first.","triggerScenarios":"Running a trace sub-command (e.g. `npx playwright trace snapshot 5`) before running `npx playwright trace open <file>`; or after the trace directory was deleted/cleaned.","commonSituations":"Fresh checkout or clean working directory; running snapshot directly after install; CI step that cleared .playwright-cli between stages.","solutions":["Run `npx playwright trace open <file>` first, then the sub-command.","Confirm you are running the commands from the same working directory where the trace was opened (the state lives in .playwright-cli/trace).","If the directory was removed, re-open the trace file to recreate it."],"exampleFix":"// before\nnpx playwright trace snapshot 5\n// after\nnpx playwright trace open trace.zip\nnpx playwright trace snapshot 5","handlingStrategy":"validation","validationCode":"import fs from 'fs';\nconst traceOpen = fs.existsSync('.playwright-cli/trace');\nif (!traceOpen) {\n  throw new Error(\"No trace opened. Run 'npx playwright trace open <file>' first.\");\n}","typeGuard":"function isTraceOpen(): boolean {\n  return fs.existsSync('.playwright-cli/trace');\n}","tryCatchPattern":null,"preventionTips":["Always run `trace open <file>` as the first step of a trace-inspection workflow.","Run trace commands from the same cwd where the trace was opened.","Avoid deleting .playwright-cli between trace sub-commands."],"tags":["trace","cli","workflow","state","validation"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}