microsoft/playwright · error · Error
Invalid ${name}: ${value}. Valid values are: ${options.join(
Error message
Invalid ${name}: ${value}. Valid values are: ${options.join(', ')} What it means
Thrown by enumParser() when a string value is not a member of the allowed options array. enumParser is a generic helper used by CLI option definitions to restrict values (e.g. browser names, snapshot modes), so the error names the option, the bad value, and the full list of legal values.
Source
Thrown at packages/playwright-core/src/tools/mcp/config.ts:602
throw new Error(`Invalid resolution format: use ${name}="800x600"`);
}
export function headerParser(arg: string | undefined, previous?: Record<string, string>): Record<string, string> | undefined {
if (!arg)
return previous;
const result: Record<string, string> = { ...(previous ?? {}) };
const colonIndex = arg.indexOf(':');
const name = colonIndex === -1 ? arg.trim() : arg.substring(0, colonIndex).trim();
const value = colonIndex === -1 ? '' : arg.substring(colonIndex + 1).trim();
result[name] = value;
return result;
}
export function enumParser<T extends string>(name: string, options: T[], value: string): T {
if (!options.includes(value as T))
throw new Error(`Invalid ${name}: ${value}. Valid values are: ${options.join(', ')}`);
return value as T;
}
function envToBoolean(value: string | undefined): boolean | undefined {
if (value === 'true' || value === '1')
return true;
if (value === 'false' || value === '0')
return false;
return undefined;
}
function envToString(value: string | undefined): string | undefined {
return value ? value.trim() : undefined;
}
View on GitHub (pinned to c8fc3bf8d3)
Solutions
- Read the 'Valid values are:' list in the error message and pick one of those exact strings.
- Check for typos and casing — the comparison is case-sensitive.
- Confirm the value is supported in your installed Playwright version (upgrade or pick a supported value).
Example fix
// before --browser safari // after --browser webkit
Defensive patterns
Strategy: validation
Validate before calling
function assertEnum<T extends string>(name: string, value: string, options: readonly T[]): T {
if (!options.includes(value as T))
throw new Error(`Invalid ${name}: ${value}. Valid: ${options.join(', ')}`);
return value as T;
} Type guard
function isOneOf<T extends string>(value: string, options: readonly T[]): value is T {
return (options as readonly string[]).includes(value);
} Prevention
- Keep a shared constant of allowed values and validate against it in your wrapper.
- Use autocomplete-friendly constants rather than free-text strings in config.
- Pin the Playwright version so the allowed value set matches what you code against.
When it happens
Trigger: Passing an unrecognized value to a constrained CLI option, e.g. `--browser safari` when only chromium/firefox/webkit/chrome variants are accepted, or a snapshot mode outside the allowed set.
Common situations: Typo in an option value; assuming a value is supported when it is not (e.g. 'safari' vs 'webkit'); version skew where a newer/older option value is not in the installed version's allowed list.
Related errors
- Invalid resolution format: use ${name}="800x600"
- Cannot use --mobile together with --device, pick one.
- --mobile is not supported with the Firefox browser.
- Device emulation is not supported with cdpEndpoint.
- Init script file does not exist: ${script}
AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12).
Data as JSON: /api/errors/7162231c0b244e00.
Report an issue: GitHub.