Skip to content

refactor: reuse Zod schemas and validate integer viewport dimensions - #3367

Merged
Lightning00Blade merged 1 commit into
mainfrom
refactor/zod-transforms-tool-definition
Oct 29, 2026
Merged

Lightning00Blade merged 1 commit into
mainfrom
refactor/zod-transforms-tool-definition

Conversation

@Lightning00Blade

@Lightning00Blade Lightning00Blade commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Replaces custom regex checks and manual parsing in viewportTransform and geolocationTransform with internal Zod object schemas, and enforces integer viewport width and height.

  • Reuses Zod schemas for numeric validation and bounds checking (latitude, longitude, width, height, deviceScaleFactor) with user-friendly validation messages (Expected an integer / Expected a number) instead of raw regex patterns.
  • Rejects non-integer viewport width and height (e.g. 1280.5x720, 1280.0x720, 1280x720.) with clear validation issues (Expected an integer), preventing CDP Emulation.setDeviceMetricsOverride protocol errors while continuing to accept fractional deviceScaleFactor.
  • Provides a descriptive validation message on viewportTagSchema when an invalid or empty viewport option is passed (e.g. Invalid viewport option "bogus". Expected "mobile", "touch", or "landscape" in '<width>x<height>x<devicePixelRatio>[,mobile][,touch][,landscape]'.).
  • Inlines intermediate variables (isMobile, hasTouch, isLandscape) in viewportTransform.
  • Forwards issue.path in zodTransform when a ZodError is caught so validation messages identify the specific failing property (for example viewport.width: Too small: expected number to be >0 or viewport.width: Expected an integer).
  • Simplifies timeoutSchema to use .transform() directly instead of wrapping with zodTransform.

Verification

  • npm run build passed.
  • npm run format passed on all changed files with 0 errors.
  • npm run test passed.

@Lightning00Blade
Lightning00Blade force-pushed the refactor/zod-transforms-tool-definition branch from 24a9877 to 03054b6 Compare October 28, 2026 16:21
@Lightning00Blade Lightning00Blade changed the title refactor: reuse Zod schemas and errors for viewport and geolocation transforms refactor: reuse Zod schemas and validate integer viewport dimensions Oct 28, 2026

@zyzyzyryxy zyzyzyryxy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few examples where I'm not happy with the new error message:

  1. Regex in the message doesn't look user friendly:
$ node build/src/bin/chrome-devtools.js emulate 1 --viewport "abcx720"
Input validation error: Invalid arguments for tool emulate: viewport.width: Invalid string: must match pattern /^[+-]?(\d+(\.\d*)?|\.\d+)$/

(the same happens for height, pixel ratio and --geolocation parameters

  1. Trailing 0s after decimal point are actually accepted, not sure if that was the intent:
$ node build/src/bin/chrome-devtools.js emulate 1 --viewport "1280.0x720.x1.5"
Emulation configured successfully
Emulating viewport: {"deviceScaleFactor":1.5,"isMobile":false,"hasTouch":false,"isLandscape":false,"width":1280,"height":720}

Comment thread src/tools/ToolDefinition.ts Resolved
Reuse Zod object schemas for numeric validation and bounds checks in viewportTransform and geolocationTransform, replacing manual decimal parsing and custom checks. Require integer width and height in viewportTransform (as CDP's Emulation.setDeviceMetricsOverride expects integers) while still supporting fractional deviceScaleFactor. Provide descriptive validation messages for numeric strings and viewport options, and forward issue paths in zodTransform so error messages identify the failing property name.
@Lightning00Blade
Lightning00Blade force-pushed the refactor/zod-transforms-tool-definition branch from 03054b6 to 16b9d25 Compare October 29, 2026 12:23
@Lightning00Blade
Lightning00Blade added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 3c609da Oct 29, 2026
18 checks passed
@Lightning00Blade
Lightning00Blade deleted the refactor/zod-transforms-tool-definition branch October 29, 2026 12:59
Lightning00Blade pushed a commit to jaeminbird/chrome-devtools-mcp that referenced this pull request Nov 11, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.13.0](ChromeDevTools/chrome-devtools-mcp@chrome-devtools-mcp-v1.12.0...chrome-devtools-mcp-v1.13.0)
(2026-11-11)


### 🎉 Features

* add logpoints built on the DevTools BreakpointManager
([ChromeDevTools#3211](ChromeDevTools#3211))
([0877ee0](ChromeDevTools@0877ee0))
* add page-scoped network mocks
([ChromeDevTools#3384](ChromeDevTools#3384))
([1d692d3](ChromeDevTools@1d692d3))
* support upstream network mock responses
([ChromeDevTools#3420](ChromeDevTools#3420))
([c4bf342](ChromeDevTools@c4bf342))


### 🛠️ Fixes

* **config:** accept config files with a UTF-8 BOM
([ChromeDevTools#3365](ChromeDevTools#3365))
([63170b1](ChromeDevTools@63170b1))
* **console:** stop resolving a cyclic Error.cause chain after 10 causes
([ChromeDevTools#3338](ChromeDevTools#3338))
([172656a](ChromeDevTools@172656a))
* disable set_logpoints when --no-javascript-evaluation is set
([ChromeDevTools#3415](ChromeDevTools#3415))
([11fcc59](ChromeDevTools@11fcc59)),
closes
[ChromeDevTools#3414](ChromeDevTools#3414)
* **extensions:** say list_extensions only lists unpacked extensions
([ChromeDevTools#3433](ChromeDevTools#3433))
([1383bb9](ChromeDevTools@1383bb9))
* ignore an invalid cached version in the update check
([ChromeDevTools#3392](ChromeDevTools#3392))
([3a9f378](ChromeDevTools@3a9f378))
* **input:** validate press_key and submitKey parameters in Zod schema
([ChromeDevTools#3382](ChromeDevTools#3382))
([375a269](ChromeDevTools@375a269))
* **network:** start an empty request list for navigations without a
request
([ChromeDevTools#3357](ChromeDevTools#3357))
([b701776](ChromeDevTools@b701776))
* normalize non-Error values thrown by tool handlers
([ChromeDevTools#3068](ChromeDevTools#3068))
([535a3dc](ChromeDevTools@535a3dc))
* **performance:** error when performance_stop_trace is called on a
non-recording page
([ChromeDevTools#2971](ChromeDevTools#2971))
([ChromeDevTools#3117](ChromeDevTools#3117))
([1ab630a](ChromeDevTools@1ab630a))
* **plugin:** launch the Claude Code MCP server with npx --prefix
([ChromeDevTools#3353](ChromeDevTools#3353))
([a24334d](ChromeDevTools@a24334d))
* preserve task serialization on request cancellation
([ChromeDevTools#3079](ChromeDevTools#3079))
([03fd4e8](ChromeDevTools@03fd4e8))
* report page loads that keep the URL
([ChromeDevTools#3395](ChromeDevTools#3395))
([3cc38bb](ChromeDevTools@3cc38bb))
* save binary request bodies byte for byte
([ChromeDevTools#3404](ChromeDevTools#3404))
([e3eb901](ChromeDevTools@e3eb901))
* suggest --headless when Chrome cannot find an X server
([ChromeDevTools#3428](ChromeDevTools#3428))
([8b0856a](ChromeDevTools@8b0856a))
* **url:** unwrap view-source: before all scheme checks in validateUrl
([ChromeDevTools#3335](ChromeDevTools#3335))
([7275268](ChromeDevTools@7275268))
* **wait:** explain whitespace-sensitive text matching
([ChromeDevTools#3350](ChromeDevTools#3350))
([81a0379](ChromeDevTools@81a0379))


### 📄 Documentation

* add Pi client configuration
([ChromeDevTools#3364](ChromeDevTools#3364))
([bc0d93e](ChromeDevTools@bc0d93e))
* clarify custom browser launch and connection options
([ChromeDevTools#3386](ChromeDevTools#3386))
([7e10c08](ChromeDevTools@7e10c08))
* **input:** note that press_key cannot drive native &lt;select&gt;
popups on macOS
([ChromeDevTools#3288](ChromeDevTools#3288))
([8e79bd0](ChromeDevTools@8e79bd0))


### ⚡ Performance

* **memory:** drop async parents of request initiators in
NetworkCollector
([ChromeDevTools#3345](ChromeDevTools#3345))
([ca6f834](ChromeDevTools@ca6f834)),
closes
[ChromeDevTools#3344](ChromeDevTools#3344)


### 🏗️ Refactor

* re-export only used Zod runtime members from third_party barrel
([ChromeDevTools#3439](ChromeDevTools#3439))
([6b056c8](ChromeDevTools@6b056c8))
* reuse Zod schemas and validate integer viewport dimensions
([ChromeDevTools#3367](ChromeDevTools#3367))
([3c609da](ChromeDevTools@3c609da))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: Alex Rudenko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants