Skip to content

emulate does not validate viewport / geolocation inputs, producing cryptic errors #2662

Description

@baishiwen9

Description of the bug

The emulate tool documents strict formats and bounds for viewport and geolocation, but the zod transforms do not validate them. Malformed input passes the tool's input-validation layer and only fails later at a lower level, with cryptic errors that do not point at the actual cause.

Reproduction

Start the server, open a page, then call emulate with invalid input:

  1. emulate with {"viewport": "abc"} → Error: Protocol error (Emulation.setDeviceMetricsOverride): Invalid parameters Failed to deserialize params.width
  2. emulate with {"geolocation": "999,999"} → Error: Invalid longitude "999": precondition -180 <= LONGITUDE <= 180 failed.

Expectation

Expected behavior

Invalid viewport / geolocation values should be rejected at the tool's input-validation layer with a clear, actionable message (consistent with other zod Input validation error responses), before any CDP call is made.

Actual behavior

Invalid values are silently parsed into NaN / out-of-range numbers and only fail later as low-level Puppeteer/CDP errors that give no hint that the input string was malformed.

MCP configuration

No response

Chrome DevTools MCP version

1.8.0

Chrome version

152

Coding agent version

No response

Model version

No response

Chat log

No response

Node version

No response

Operating system

None

Extra checklist

  • I want to provide a PR to fix this bug

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions