microsoft/playwright · error · Error
No trace opened. Run 'npx playwright trace open <file>' firs
Error message
No trace opened. Run 'npx playwright trace open <file>' first.
What it means
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.
Source
Thrown at packages/playwright-core/src/tools/trace/traceUtils.ts:57
this.loader = loader;
this.ordinalToCallId = ordinals.ordinalToCallId;
this.callIdToOrdinal = ordinals.callIdToOrdinal;
}
resolveActionId(actionId: string): ActionEntry | undefined {
const ordinal = parseInt(actionId, 10);
if (!isNaN(ordinal)) {
const callId = this.ordinalToCallId.get(ordinal);
if (callId)
return this.model.actions.find(a => a.callId === callId);
}
return this.model.actions.find(a => a.callId === actionId);
}
}
function ensureTraceOpen(): string {
if (!fs.existsSync(traceDir))
throw new Error(`No trace opened. Run 'npx playwright trace open <file>' first.`);
return traceDir;
}
export async function closeTrace() {
if (fs.existsSync(traceDir))
await fs.promises.rm(traceDir, { recursive: true });
}
export async function openTrace(traceFile: string) {
const filePath = path.resolve(traceFile);
if (!fs.existsSync(filePath))
throw new Error(`Trace file not found: ${filePath}`);
await closeTrace();
await fs.promises.mkdir(traceDir, { recursive: true });
if (filePath.endsWith('.zip'))
await extractTrace(filePath, traceDir);
else
await fs.promises.writeFile(path.join(traceDir, '.link'), filePath, 'utf-8');View on GitHub (pinned to c8fc3bf8d3)
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.
Example fix
// before npx playwright trace snapshot 5 // after npx playwright trace open trace.zip npx playwright trace snapshot 5
Defensive patterns
Strategy: validation
Validate before calling
import fs from 'fs';
const traceOpen = fs.existsSync('.playwright-cli/trace');
if (!traceOpen) {
throw new Error("No trace opened. Run 'npx playwright trace open <file>' first.");
} Type guard
function isTraceOpen(): boolean {
return fs.existsSync('.playwright-cli/trace');
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Fresh checkout or clean working directory; running snapshot directly after install; CI step that cleared .playwright-cli between stages.
Related errors
- Unknown command: ${args._[0]}
- Trace file not found: ${filePath}
- Cannot find .trace file
- Invalid viewport size format: use "width,height", for exampl
- Invalid geolocation format, should be "lat,long". For exampl
AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12).
Data as JSON: /api/errors/2224873a8da1bfd8.
Report an issue: GitHub.