microsoft/playwright · error · Error
Command is required
Error message
Command is required
What it means
Thrown by `parseCliCommand` when `commands[args._[0]]` is falsy, i.e. the first positional argument does not match any registered CLI command name. This covers both an empty argument list and an unrecognized command name.
Source
Thrown at packages/playwright-core/src/tools/cli-daemon/daemon.ts:147
async function deleteSessionFile(clientInfo: ClientInfo, sessionConfig: SessionConfig) {
await fs.promises.unlink(sessionConfig.socketPath).catch(() => {});
if (!sessionConfig.cli.persistent) {
const sessionFile = path.join(clientInfo.daemonProfilesDir, `${sessionConfig.name}.session`);
await fs.promises.rm(sessionFile).catch(() => {});
}
}
function formatResult(result: CallToolResult) {
const isError = result.isError;
const text = result.content[0].type === 'text' ? result.content[0].text : undefined;
return { isError, text };
}
function parseCliCommand(args: Record<string, string> & { _: string[] }): { toolName: string, toolParams: NonNullable<CallToolRequest['params']['arguments']> } {
const command = commands[args._[0]];
if (!command)
throw new Error('Command is required');
return parseCommand(command, args);
}
function daemonSocketPath(clientInfo: ClientInfo, sessionName: string): string {
return makeSocketPath('cli', `${clientInfo.workspaceDirHash}-${sessionName}`);
}
function createSessionConfig(clientInfo: ClientInfo, sessionName: string, browserInfo: BrowserInfo, options: {
ownership?: 'attached' | 'own',
persistent?: boolean,
exitOnStop?: boolean,
} = {}): SessionConfig {
return {
name: sessionName,
version: clientInfo.version,
timestamp: Date.now(),
socketPath: daemonSocketPath(clientInfo, sessionName),
workspaceDir: clientInfo.workspaceDir,View on GitHub (pinned to c8fc3bf8d3)
Solutions
- Ensure `params.args._[0]` is a valid command name (e.g. `click`, `fill`, `screenshot`, `drop`).
- If unsure of available commands, list them from the commands registry / `--help` output.
- Check that argument parsing in the client preserves positional args in `_` (yargs-style) rather than dropping them.
Example fix
// before
{ args: { _: [], target: 'ref' } }
// after
{ args: { _: ['click'], target: 'ref' } } Defensive patterns
Strategy: validation
Validate before calling
// Ensure a command name is present and recognized before sending.
const KNOWN_COMMANDS = new Set(['click', 'fill', 'hover', 'screenshot', 'drop', /* ... */]);
function buildRunArgs(positional: string[]) {
if (!positional.length || !KNOWN_COMMANDS.has(positional[0]))
throw new TypeError(`Unknown or missing command: ${positional[0] ?? '(none)'}`);
return { _: positional };
} Type guard
function hasCommand(args: { _: string[] }): args is { _: [string, ...string[]] } {
return args._.length > 0;
} Prevention
- Always include a command name as the first positional argument.
- Validate against the command registry before dispatching.
- Keep client/daemon versions aligned so command sets match.
When it happens
Trigger: Invoking the daemon `run` method with `params.args._` being empty, or with a first element that is not a registered command (e.g. a typo, an internal-only name, or a command removed in this version).
Common situations: Client sends a bare `run` with no command (e.g. just flags); user types a command name that doesn't exist (`'sreenshot'`); version mismatch where a command was renamed; a wrapper script that strips the command token before forwarding.
Related errors
- --data must be in "mime/type=value" format, got: ${entry}
- boolean option '--${key}' should not be passed with '=value'
- Could not start the session "${sessionName}"
- Client is v${clientInfo.version}, session '${this.name}' is
- Browser '${this.name}' is not open. Run playwright-cli${t
AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12).
Data as JSON: /api/errors/3aea21ce42f29707.
Report an issue: GitHub.