microsoft/playwright · error · Error
Invalid resolution format: use ${name}="800x600"
Error message
Invalid resolution format: use ${name}="800x600" What it means
Thrown by resolutionParser() when the value contains an 'x' separator but the two halves cannot be parsed into two positive numbers (NaN, zero, or negative). This parser backs --viewport-style CLI options, so the error fires during argument parsing, before any browser is launched.
Source
Thrown at packages/playwright-core/src/tools/mcp/config.ts:573
export function dotenvFileLoader(value: string | undefined): Record<string, string> | undefined {
if (!value)
return undefined;
return dotenv.parse(fs.readFileSync(value, 'utf8'));
}
export function numberParser(value: string | undefined): number | undefined {
if (!value)
return undefined;
return +value;
}
export function resolutionParser(name: string, value: string | undefined): ViewportSize | undefined {
if (!value)
return undefined;
if (value.includes('x')) {
const [width, height] = value.split('x').map(v => +v);
if (isNaN(width) || isNaN(height) || width <= 0 || height <= 0)
throw new Error(`Invalid resolution format: use ${name}="800x600"`);
return { width, height };
}
// Legacy format
if (value.includes(',')) {
const [width, height] = value.split(',').map(v => +v);
if (isNaN(width) || isNaN(height) || width <= 0 || height <= 0)
throw new Error(`Invalid resolution format: use ${name}="800x600"`);
return { width, height };
}
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 ?? {}) };View on GitHub (pinned to c8fc3bf8d3)
Solutions
- Provide two positive integers separated by a single ASCII 'x', e.g. `--viewport 800x600`.
- If the value comes from a variable, validate/sanitize it before passing it to the CLI.
- Ensure you used the ASCII letter 'x' and not a multiplication sign or capital 'X' adjacent to a non-numeric string.
Example fix
// before --viewport 800x600px // after --viewport 800x600
Defensive patterns
Strategy: validation
Validate before calling
function parseResolution(v: string): { width: number; height: number } {
const m = /^(\d+)x(\d+)$/.exec(v);
if (!m) throw new Error(`Invalid resolution: ${v}. Use WIDTHxHEIGHT, e.g. 800x600.`);
const [w, h] = [+m[1], +m[2]];
if (w <= 0 || h <= 0) throw new Error('Width and height must be positive.');
return { width: w, height: h };
} Type guard
function isValidResolution(v: string): boolean {
const m = /^(\d+)x(\d+)$/.exec(v);
return !!m && +m[1] > 0 && +m[2] > 0;
} Prevention
- Validate resolution strings with a WIDTHxHEIGHT regex before passing to the CLI.
- Normalize values (strip units, replace multiplication signs) in your own code.
- Treat viewport as structured data ({width,height}) until the moment you serialize it.
When it happens
Trigger: Passing a viewport/resolution value like `--viewport 800x`, `--viewport x600`, `--viewport axb`, or `--viewport 0x600`.
Common situations: Typo in the dimensions; copy-pasting a value with a multiplication sign (×, U+00D7) instead of ASCII 'x'; trailing units like `800x600px`; negative or zero values from a variable.
Related errors
- Invalid ${name}: ${value}. Valid values are: ${options.join(
- Cannot use --mobile together with --device, pick one.
- --mobile is not supported with the Firefox browser.
- Device emulation is not supported with cdpEndpoint.
- Invalid viewport size format: use "width,height", for exampl
AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12).
Data as JSON: /api/errors/ba163bd1ec600611.
Report an issue: GitHub.