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

  1. Read the 'Valid values are:' list in the error message and pick one of those exact strings.
  2. Check for typos and casing — the comparison is case-sensitive.
  3. 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

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


AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12). Data as JSON: /api/errors/7162231c0b244e00. Report an issue: GitHub.