Chrome DevTools for coding agents
refactor: group Puppeteer and tool options (#2875)
Nikolay Vitkov699c4d5870b6
diff --git a/docs/configuration.md b/docs/configuration.mdindex 1e30afbc..877ce433 100644--- a/docs/configuration.md+++ b/docs/configuration.md@@ -112,10 +112,6 @@ The Chrome DevTools MCP server supports the following configuration option:Explicitly disable default arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.- **Type:** array-- **`--logFile`/ `--log-file`**- Path to a file to write debug logs to. Set the env variable `NODE_DEBUG` to `*` to enable verbose logs. Useful for submitting bug reports.- - **Type:** string-- **`--viewport`**Initial viewport size for the Chrome instances started by the server. For example, `1280x720`. In headless mode, max size is 3840x2160px.- **Type:** string@@ -125,6 +121,36 @@ The Chrome DevTools MCP server supports the following configuration option:- **Type:** boolean- **Default:** `false`+- **`--blockedUrlPattern`/ `--blocked-url-pattern`**+ Restricts browser's network access by blocking specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Silently detaches from targets with blocked URLs upon connection, and blocks runtime requests (including navigations and subresources). Accepts an array of patterns. A pattern that uses a regexp group in any component (for example `(127\.\d+\.\d+\.\d+)` in the hostname) is rejected, because it is not enforced on redirects or subresources; use an exact value or a `*`/`:name` wildcard instead.+ - **Type:** array++- **`--allowedUrlPattern`/ `--allowed-url-pattern`**+ Restricts browser's network access by allowing only specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Requires Chrome 149+. Silently detaches from targets with unallowed URLs upon connection, and blocks runtime requests (including navigations and subresources). Accepts an array of patterns. A pattern that uses a regexp group in any component (for example `(127\.\d+\.\d+\.\d+)` in the hostname) is rejected, because it is not enforced on redirects or subresources; use an exact value or a `*`/`:name` wildcard instead.+ - **Type:** array++- **`--screenshotFormat`/ `--screenshot-format`**+ Override the default output format used by take_screenshot when the caller does not specify one. JPEG and WebP are ~3-5x smaller than PNG, which reduces transfer and storage size. To reduce context size use --screenshotMaxWidth / --screenshotMaxHeight, since image tokens scale with dimensions rather than encoded bytes. Unset preserves the existing default ("png").+ - **Type:** string+ - **Choices:** `jpeg`, `png`, `webp`+ - **Default:** `png`++- **`--screenshotQuality`/ `--screenshot-quality`**+ Override the default compression quality (0-100) used by take_screenshot for JPEG and WebP when the caller does not specify one. Lower values mean smaller files. Ignored for PNG. Unset preserves the Puppeteer default.+ - **Type:** number++- **`--screenshotMaxWidth`/ `--screenshot-max-width`**+ Maximum width in pixels for screenshots. If the captured image is wider, it is downscaled (preserving aspect ratio) before being returned. Reduces context size in AI conversations. Unset means no resize.+ - **Type:** number++- **`--screenshotMaxHeight`/ `--screenshot-max-height`**+ Maximum height in pixels for screenshots. If the captured image is taller, it is downscaled (preserving aspect ratio) before being returned. Can be combined with --screenshot-max-width; the smaller scale factor wins. Unset means no resize.+ - **Type:** number++- **`--logFile`/ `--log-file`**+ Path to a file to write debug logs to. Set the env variable `NODE_DEBUG` to `*` to enable verbose logs. Useful for submitting bug reports.+ - **Type:** string+- **`--pageIdRouting`/ `--page-id-routing`**Require pageId on page-scoped tools and route requests by page ID (useful for concurrent agent sessions). Use --no-page-id-routing to disable.- **Type:** boolean@@ -168,14 +194,6 @@ The Chrome DevTools MCP server supports the following configuration option:Frames per second to use for screencast recording. Lower values can reduce memory pressure on pages that produce frames faster than ffmpeg can encode them.- **Type:** number-- **`--blockedUrlPattern`/ `--blocked-url-pattern`**- Restricts browser's network access by blocking specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Silently detaches from targets with blocked URLs upon connection, and blocks runtime requests (including navigations and subresources). Accepts an array of patterns. A pattern that uses a regexp group in any component (for example `(127\.\d+\.\d+\.\d+)` in the hostname) is rejected, because it is not enforced on redirects or subresources; use an exact value or a `*`/`:name` wildcard instead.- - **Type:** array--- **`--allowedUrlPattern`/ `--allowed-url-pattern`**- Restricts browser's network access by allowing only specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Requires Chrome 149+. Silently detaches from targets with unallowed URLs upon connection, and blocks runtime requests (including navigations and subresources). Accepts an array of patterns. A pattern that uses a regexp group in any component (for example `(127\.\d+\.\d+\.\d+)` in the hostname) is rejected, because it is not enforced on redirects or subresources; use an exact value or a `*`/`:name` wildcard instead.- - **Type:** array-- **`--performanceCrux`/ `--performance-crux`**Set to false to disable sending URLs from performance traces to CrUX API to get field performance data.- **Type:** boolean@@ -196,24 +214,6 @@ The Chrome DevTools MCP server supports the following configuration option:- **Type:** boolean- **Default:** `true`-- **`--screenshotFormat`/ `--screenshot-format`**- Override the default output format used by take_screenshot when the caller does not specify one. JPEG and WebP are ~3-5x smaller than PNG, which reduces transfer and storage size. To reduce context size use --screenshotMaxWidth / --screenshotMaxHeight, since image tokens scale with dimensions rather than encoded bytes. Unset preserves the existing default ("png").- - **Type:** string- - **Choices:** `jpeg`, `png`, `webp`- - **Default:** `png`--- **`--screenshotQuality`/ `--screenshot-quality`**- Override the default compression quality (0-100) used by take_screenshot for JPEG and WebP when the caller does not specify one. Lower values mean smaller files. Ignored for PNG. Unset preserves the Puppeteer default.- - **Type:** number--- **`--screenshotMaxWidth`/ `--screenshot-max-width`**- Maximum width in pixels for screenshots. If the captured image is wider, it is downscaled (preserving aspect ratio) before being returned. Reduces context size in AI conversations. Unset means no resize.- - **Type:** number--- **`--screenshotMaxHeight`/ `--screenshot-max-height`**- Maximum height in pixels for screenshots. If the captured image is taller, it is downscaled (preserving aspect ratio) before being returned. Can be combined with --screenshot-max-width; the smaller scale factor wins. Unset means no resize.- - **Type:** number-- **`--slim`**Exposes a "slim" set of 3 tools covering navigation, script execution and screenshots only. Useful for basic browser tasks.- **Type:** booleandiff --git a/src/config/mcp-options.ts b/src/config/mcp-options.tsindex 62b581e8..dfe2d91d 100644--- a/src/config/mcp-options.ts+++ b/src/config/mcp-options.ts@@ -10,42 +10,21 @@ import path from 'node:path';export const DEFAULT_FILESYSTEM_ROOT = [os.tmpdir()];-import {findUnenforceablePattern} from '../utils/url.js';-import {getCategoryOptions} from './category-options.js';import {getBrowserOptions} from './browser-options.js';+import {puppeteerOptions} from './puppeteer-options.js';+import {toolOptions} from './tool-options.js';export const mcpOptions = {...getCategoryOptions(),...getBrowserOptions(),+ ...puppeteerOptions,+ ...toolOptions,logFile: {type: 'string',describe:'Path to a file to write debug logs to. Set the env variable `NODE_DEBUG` to `*` to enable verbose logs. Useful for submitting bug reports.',},- viewport: {- type: 'string',- describe:- 'Initial viewport size for the Chrome instances started by the server. For example, `1280x720`. In headless mode, max size is 3840x2160px.',- coerce: (arg: string | undefined) => {- if (arg === undefined) {- return;- }- const [width, height] = arg.split('x').map(Number);- if (!width || !height || Number.isNaN(width) || Number.isNaN(height)) {- throw new Error('Invalid viewport. Expected format is `1280x720`.');- }- return {- width,- height,- };- },- },- acceptInsecureCerts: {- type: 'boolean',- default: false,- description: `If enabled, ignores errors relative to self-signed and expired certificates. Use with caution.`,- },pageIdRouting: {type: 'boolean',describe:@@ -134,47 +113,6 @@ export const mcpOptions = {return value;},},- blockedUrlPattern: {- type: 'array',- string: true,- describe:- "Restricts browser's network access by blocking specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Silently detaches from targets with blocked URLs upon connection, and blocks runtime requests (including navigations and subresources). Accepts an array of patterns. A pattern that uses a regexp group in any component (for example `(127\\.\\d+\\.\\d+\\.\\d+)` in the hostname) is rejected, because it is not enforced on redirects or subresources; use an exact value or a `*`/`:name` wildcard instead.",- coerce: (arg: string[] | undefined) => {- if (arg === undefined || arg.length === 0) {- return undefined;- }- const pattern = findUnenforceablePattern(arg);- if (pattern) {- throw new Error(- `Invalid --blockedUrlPattern "${pattern}": a regexp group is not enforced on redirects or subresources. Use an exact value or a "*"/":name" wildcard instead.`,- );- }- return arg;- },- },- allowedUrlPattern: {- type: 'array',- string: true,- describe:- "Restricts browser's network access by allowing only specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Requires Chrome 149+. Silently detaches from targets with unallowed URLs upon connection, and blocks runtime requests (including navigations and subresources). Accepts an array of patterns. A pattern that uses a regexp group in any component (for example `(127\\.\\d+\\.\\d+\\.\\d+)` in the hostname) is rejected, because it is not enforced on redirects or subresources; use an exact value or a `*`/`:name` wildcard instead.",- coerce: (arg: string[] | undefined) => {- if (arg === undefined) {- return undefined;- }- if (arg.length === 0) {- throw new Error(- 'Invalid --allowedUrlPattern: at least one pattern is required.',- );- }- const pattern = findUnenforceablePattern(arg);- if (pattern) {- throw new Error(- `Invalid --allowedUrlPattern "${pattern}": a regexp group is not enforced on redirects or subresources. Use an exact value or a "*"/":name" wildcard instead.`,- );- }- return arg;- },- },performanceCrux: {type: 'boolean',default: true,@@ -215,61 +153,6 @@ export const mcpOptions = {hidden: true,describe: 'Include watchdog PID in Clearcut request headers (for testing).',},- screenshotFormat: {- type: 'string',- default: 'png' as const,- description:- 'Override the default output format used by take_screenshot when the caller does not specify one. JPEG and WebP are ~3-5x smaller than PNG, which reduces transfer and storage size. To reduce context size use --screenshotMaxWidth / --screenshotMaxHeight, since image tokens scale with dimensions rather than encoded bytes. Unset preserves the existing default ("png").',- choices: ['jpeg', 'png', 'webp'] as const,- },- screenshotQuality: {- type: 'number',- description:- 'Override the default compression quality (0-100) used by take_screenshot for JPEG and WebP when the caller does not specify one. Lower values mean smaller files. Ignored for PNG. Unset preserves the Puppeteer default.',- coerce: (value: number | undefined) => {- if (value === undefined) {- return;- }- if (!Number.isInteger(value) || value < 0 || value > 100) {- throw new Error(- `Invalid screenshotQuality ${value}. Expected an integer between 0 and 100.`,- );- }- return value;- },- },- screenshotMaxWidth: {- type: 'number',- description:- 'Maximum width in pixels for screenshots. If the captured image is wider, it is downscaled (preserving aspect ratio) before being returned. Reduces context size in AI conversations. Unset means no resize.',- coerce: (value: number | undefined) => {- if (value === undefined) {- return;- }- if (!Number.isInteger(value) || value <= 0) {- throw new Error(- `Invalid screenshotMaxWidth ${value}. Expected a positive integer.`,- );- }- return value;- },- },- screenshotMaxHeight: {- type: 'number',- description:- 'Maximum height in pixels for screenshots. If the captured image is taller, it is downscaled (preserving aspect ratio) before being returned. Can be combined with --screenshot-max-width; the smaller scale factor wins. Unset means no resize.',- coerce: (value: number | undefined) => {- if (value === undefined) {- return;- }- if (!Number.isInteger(value) || value <= 0) {- throw new Error(- `Invalid screenshotMaxHeight ${value}. Expected a positive integer.`,- );- }- return value;- },- },slim: {type: 'boolean',default: false,diff --git a/src/config/puppeteer-options.ts b/src/config/puppeteer-options.tsnew file mode 100644index 00000000..21eefd7e--- /dev/null+++ b/src/config/puppeteer-options.ts@@ -0,0 +1,79 @@+/**+ * @license+ * Copyright 2026 Google LLC+ * SPDX-License-Identifier: Apache-2.0+ */++import type {YargsOptions} from '../third_party/index.js';+import {findUnenforceablePattern} from '../utils/url.js';++/**+ * Options that are applied through Puppeteer when launching or connecting to+ * the browser.+ */+export const puppeteerOptions = {+ viewport: {+ type: 'string',+ describe:+ 'Initial viewport size for the Chrome instances started by the server. For example, `1280x720`. In headless mode, max size is 3840x2160px.',+ coerce: (arg: string | undefined) => {+ if (arg === undefined) {+ return;+ }+ const [width, height] = arg.split('x').map(Number);+ if (!width || !height || Number.isNaN(width) || Number.isNaN(height)) {+ throw new Error('Invalid viewport. Expected format is `1280x720`.');+ }+ return {+ width,+ height,+ };+ },+ },+ acceptInsecureCerts: {+ type: 'boolean',+ default: false,+ description: `If enabled, ignores errors relative to self-signed and expired certificates. Use with caution.`,+ },+ blockedUrlPattern: {+ type: 'array',+ string: true,+ describe:+ "Restricts browser's network access by blocking specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Silently detaches from targets with blocked URLs upon connection, and blocks runtime requests (including navigations and subresources). Accepts an array of patterns. A pattern that uses a regexp group in any component (for example `(127\\.\\d+\\.\\d+\\.\\d+)` in the hostname) is rejected, because it is not enforced on redirects or subresources; use an exact value or a `*`/`:name` wildcard instead.",+ coerce: (arg: string[] | undefined) => {+ if (arg === undefined || arg.length === 0) {+ return undefined;+ }+ const pattern = findUnenforceablePattern(arg);+ if (pattern) {+ throw new Error(+ `Invalid --blockedUrlPattern "${pattern}": a regexp group is not enforced on redirects or subresources. Use an exact value or a "*"/":name" wildcard instead.`,+ );+ }+ return arg;+ },+ },+ allowedUrlPattern: {+ type: 'array',+ string: true,+ describe:+ "Restricts browser's network access by allowing only specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Requires Chrome 149+. Silently detaches from targets with unallowed URLs upon connection, and blocks runtime requests (including navigations and subresources). Accepts an array of patterns. A pattern that uses a regexp group in any component (for example `(127\\.\\d+\\.\\d+\\.\\d+)` in the hostname) is rejected, because it is not enforced on redirects or subresources; use an exact value or a `*`/`:name` wildcard instead.",+ coerce: (arg: string[] | undefined) => {+ if (arg === undefined) {+ return undefined;+ }+ if (arg.length === 0) {+ throw new Error(+ 'Invalid --allowedUrlPattern: at least one pattern is required.',+ );+ }+ const pattern = findUnenforceablePattern(arg);+ if (pattern) {+ throw new Error(+ `Invalid --allowedUrlPattern "${pattern}": a regexp group is not enforced on redirects or subresources. Use an exact value or a "*"/":name" wildcard instead.`,+ );+ }+ return arg;+ },+ },+} satisfies Record<string, YargsOptions>;diff --git a/src/config/tool-options.ts b/src/config/tool-options.tsnew file mode 100644index 00000000..71b0295d--- /dev/null+++ b/src/config/tool-options.ts@@ -0,0 +1,68 @@+/**+ * @license+ * Copyright 2026 Google LLC+ * SPDX-License-Identifier: Apache-2.0+ */++import type {YargsOptions} from '../third_party/index.js';++/**+ * Options that change the default behavior of tools.+ */+export const toolOptions = {+ screenshotFormat: {+ type: 'string',+ default: 'png' as const,+ description:+ 'Override the default output format used by take_screenshot when the caller does not specify one. JPEG and WebP are ~3-5x smaller than PNG, which reduces transfer and storage size. To reduce context size use --screenshotMaxWidth / --screenshotMaxHeight, since image tokens scale with dimensions rather than encoded bytes. Unset preserves the existing default ("png").',+ choices: ['jpeg', 'png', 'webp'] as const,+ },+ screenshotQuality: {+ type: 'number',+ description:+ 'Override the default compression quality (0-100) used by take_screenshot for JPEG and WebP when the caller does not specify one. Lower values mean smaller files. Ignored for PNG. Unset preserves the Puppeteer default.',+ coerce: (value: number | undefined) => {+ if (value === undefined) {+ return;+ }+ if (!Number.isInteger(value) || value < 0 || value > 100) {+ throw new Error(+ `Invalid screenshotQuality ${value}. Expected an integer between 0 and 100.`,+ );+ }+ return value;+ },+ },+ screenshotMaxWidth: {+ type: 'number',+ description:+ 'Maximum width in pixels for screenshots. If the captured image is wider, it is downscaled (preserving aspect ratio) before being returned. Reduces context size in AI conversations. Unset means no resize.',+ coerce: (value: number | undefined) => {+ if (value === undefined) {+ return;+ }+ if (!Number.isInteger(value) || value <= 0) {+ throw new Error(+ `Invalid screenshotMaxWidth ${value}. Expected a positive integer.`,+ );+ }+ return value;+ },+ },+ screenshotMaxHeight: {+ type: 'number',+ description:+ 'Maximum height in pixels for screenshots. If the captured image is taller, it is downscaled (preserving aspect ratio) before being returned. Can be combined with --screenshot-max-width; the smaller scale factor wins. Unset means no resize.',+ coerce: (value: number | undefined) => {+ if (value === undefined) {+ return;+ }+ if (!Number.isInteger(value) || value <= 0) {+ throw new Error(+ `Invalid screenshotMaxHeight ${value}. Expected a positive integer.`,+ );+ }+ return value;+ },+ },+} satisfies Record<string, YargsOptions>;