microsoft/playwright · error · Error
Unknown command: ${args._[0]}
Error message
Unknown command: ${args._[0]} What it means
Thrown by runCommandOnSnapshot() when the first positional argument (args._[0]) is not a key in the commands map. After a trace snapshot page is served in a headless browser, the CLI dispatches a sub-command against it; an unrecognized sub-command name is rejected here. The command list is imported from the cli-daemon commands module.
Source
Thrown at packages/playwright-core/src/tools/trace/traceSnapshot.ts:203
const browser = await playwright.chromium.launch({ headless: true });
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(server.url);
await page.waitForURL(url => new URL(url).pathname.startsWith('/snapshot/'));
const backend = new BrowserBackend({
snapshot: { mode: 'full' },
skillMode: true,
}, context, browserTools);
await backend.initialize({ cwd: process.cwd(), clientName: 'playwright-cli' });
try {
if (!browserArgs.length)
browserArgs = ['snapshot'];
const args = minimist(browserArgs, { string: ['_'] });
const command = commands[args._[0]];
if (!command)
throw new Error(`Unknown command: ${args._[0]}`);
const { toolName, toolParams } = parseCommand(command, args as Record<string, string> & { _: string[] });
const result = await backend.callTool(toolName, toolParams);
const text = result.content[0]?.type === 'text' ? result.content[0].text : undefined;
if (text)
console.log(text);
if (result.isError) {
console.error('Command failed.');
process.exitCode = 1;
}
} catch (e) {
console.error((e as Error).message);
process.exitCode = 1;
} finally {
await server.stop().catch(e => console.error(e));
await gracefullyCloseAll();
}
}
View on GitHub (pinned to c8fc3bf8d3)
Solutions
- Check the registered command names for your installed Playwright version and use an exact match.
- If you only want to view the snapshot, omit the extra positional argument (the default is 'snapshot').
- Upgrade or downgrade Playwright to the version whose command set you are targeting.
Example fix
// before npx playwright trace snapshot 5 slect option // after npx playwright trace snapshot 5 select option
Defensive patterns
Strategy: validation
Validate before calling
import { commands } from '../cli-daemon/commands';
function assertKnownCommand(name: string) {
if (!(name in commands)) {
throw new Error(`Unknown command: ${name}. Known: ${Object.keys(commands).join(', ')}`);
}
} Type guard
function isKnownCommand(name: string): name is keyof typeof commands {
return name in commands;
} Prevention
- Validate the sub-command against the installed version's command list before dispatch.
- Avoid passing free-text user input directly as the sub-command position.
- Pin the Playwright version so the command set is stable.
When it happens
Trigger: Running `npx playwright trace snapshot <actionId> <subcommand>` where <subcommand> is not one of the registered snapshot sub-commands (e.g. a typo like 'slect' instead of 'select').
Common situations: Typo in the sub-command; using a command name from a different/newer Playwright version not present in the installed one; passing a flag in the command position by mistake.
Related errors
- No trace opened. Run 'npx playwright trace open <file>' firs
- 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/db29212b2826a368.
Report an issue: GitHub.