Skip to content

Commit 394fbd2

Browse files
bcfmtolgahanTolgahan Demirbaş
authored andcommitted
feat: make pageId routing always-on
Remove the --experimental-page-id-routing gate so pageId is always exposed on page-scoped tools. Update evaluate_script which had its own duplicate gate. Fix docs generator to include pageId for page-scoped tools. Regenerate cliDefinitions.ts and tool-reference.md. - Remove experimentalPageIdRouting conditions from schema injection and page resolution in index.ts - Mark --experimental-page-id-routing CLI flag as deprecated - Improve pageIdSchema description to be more helpful - Remove evaluate_script's own experimentalPageIdRouting gate; also fixes a latent bug where getPageById(undefined) was called when the flag was on but pageId was absent - Fix pageId type in script.test.ts (string -> number) - Fix generate-docs.ts to inject pageIdSchema for page-scoped tools so tool-reference.md accurately reflects available parameters
1 parent e513db1 commit 394fbd2

File tree

8 files changed

+210
-16
lines changed

8 files changed

+210
-16
lines changed

docs/tool-reference.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- AUTO GENERATED DO NOT EDIT - run 'npm run gen' to update-->
22

3-
# Chrome DevTools MCP Tool Reference (~6949 cl100k_base tokens)
3+
# Chrome DevTools MCP Tool Reference (~8124 cl100k_base tokens)
44

55
- **[Input automation](#input-automation)** (9 tools)
66
- [`click`](#click)
@@ -49,6 +49,7 @@
4949
- **uid** (string) **(required)**: The uid of an element on the page from the page content snapshot
5050
- **dblClick** (boolean) _(optional)_: Set to true for double clicks. Default is false.
5151
- **includeSnapshot** (boolean) _(optional)_: Whether to include a snapshot in the response. Default is false.
52+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
5253

5354
---
5455

@@ -61,6 +62,7 @@
6162
- **from_uid** (string) **(required)**: The uid of the element to [`drag`](#drag)
6263
- **to_uid** (string) **(required)**: The uid of the element to drop into
6364
- **includeSnapshot** (boolean) _(optional)_: Whether to include a snapshot in the response. Default is false.
65+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
6466

6567
---
6668

@@ -73,6 +75,7 @@
7375
- **uid** (string) **(required)**: The uid of an element on the page from the page content snapshot
7476
- **value** (string) **(required)**: The value to [`fill`](#fill) in
7577
- **includeSnapshot** (boolean) _(optional)_: Whether to include a snapshot in the response. Default is false.
78+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
7679

7780
---
7881

@@ -84,6 +87,7 @@
8487

8588
- **elements** (array) **(required)**: Elements from snapshot to [`fill`](#fill) out.
8689
- **includeSnapshot** (boolean) _(optional)_: Whether to include a snapshot in the response. Default is false.
90+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
8791

8892
---
8993

@@ -94,6 +98,7 @@
9498
**Parameters:**
9599

96100
- **action** (enum: "accept", "dismiss") **(required)**: Whether to dismiss or accept the dialog
101+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
97102
- **promptText** (string) _(optional)_: Optional prompt text to enter into the dialog.
98103

99104
---
@@ -106,6 +111,7 @@
106111

107112
- **uid** (string) **(required)**: The uid of an element on the page from the page content snapshot
108113
- **includeSnapshot** (boolean) _(optional)_: Whether to include a snapshot in the response. Default is false.
114+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
109115

110116
---
111117

@@ -117,6 +123,7 @@
117123

118124
- **key** (string) **(required)**: A key or a combination (e.g., "Enter", "Control+A", "Control++", "Control+Shift+R"). Modifiers: Control, Shift, Alt, Meta
119125
- **includeSnapshot** (boolean) _(optional)_: Whether to include a snapshot in the response. Default is false.
126+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
120127

121128
---
122129

@@ -127,6 +134,7 @@
127134
**Parameters:**
128135

129136
- **text** (string) **(required)**: The text to type
137+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
130138
- **submitKey** (string) _(optional)_: Optional key to press after typing. E.g., "Enter", "Tab", "Escape"
131139

132140
---
@@ -140,6 +148,7 @@
140148
- **filePath** (string) **(required)**: The local path of the file to upload
141149
- **uid** (string) **(required)**: The uid of the file input element or an element that will open file chooser on the page from the page content snapshot
142150
- **includeSnapshot** (boolean) _(optional)_: Whether to include a snapshot in the response. Default is false.
151+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
143152

144153
---
145154

@@ -172,6 +181,7 @@
172181
- **handleBeforeUnload** (enum: "accept", "decline") _(optional)_: Whether to auto accept or beforeunload dialogs triggered by this navigation. Default is accept.
173182
- **ignoreCache** (boolean) _(optional)_: Whether to ignore cache on reload.
174183
- **initScript** (string) _(optional)_: A JavaScript script to be executed on each new document before any other scripts for the next navigation.
184+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
175185
- **timeout** (integer) _(optional)_: Maximum wait time in milliseconds. If set to 0, the default timeout will be used.
176186
- **type** (enum: "url", "back", "forward", "reload") _(optional)_: Navigate the page by URL, back or forward in history, or reload.
177187
- **url** (string) _(optional)_: Target URL (only type=url)
@@ -209,6 +219,7 @@
209219
**Parameters:**
210220

211221
- **text** (array) **(required)**: Non-empty list of texts. Resolves when any value appears on the page.
222+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
212223
- **timeout** (integer) _(optional)_: Maximum wait time in milliseconds. If set to 0, the default timeout will be used.
213224

214225
---
@@ -225,6 +236,7 @@
225236
- **cpuThrottlingRate** (number) _(optional)_: Represents the CPU slowdown factor. Omit or set the rate to 1 to disable throttling
226237
- **geolocation** (string) _(optional)_: Geolocation (`&lt;latitude&gt;x&lt;longitude&gt;`) to [`emulate`](#emulate). Latitude between -90 and 90. Longitude between -180 and 180. Omit clear the geolocation override.
227238
- **networkConditions** (enum: "Offline", "Slow 3G", "Fast 3G", "Slow 4G", "Fast 4G") _(optional)_: Throttle network. Omit to disable throttling.
239+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
228240
- **userAgent** (string) _(optional)_: User agent to [`emulate`](#emulate). Set to empty string to clear the user agent override.
229241
- **viewport** (string) _(optional)_: [`Emulate`](#emulate) device viewports '&lt;width&gt;x&lt;height&gt;x&lt;devicePixelRatio&gt;[,mobile][,touch][,landscape]'. 'touch' and 'mobile' to [`emulate`](#emulate) mobile devices. 'landscape' to [`emulate`](#emulate) landscape mode.
230242

@@ -238,6 +250,7 @@
238250

239251
- **height** (number) **(required)**: Page height
240252
- **width** (number) **(required)**: Page width
253+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
241254

242255
---
243256

@@ -251,6 +264,7 @@
251264

252265
- **insightName** (string) **(required)**: The name of the Insight you want more information on. For example: "DocumentLatency" or "LCPBreakdown"
253266
- **insightSetId** (string) **(required)**: The id for the specific insight set. Only use the ids given in the "Available insight sets" list.
267+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
254268

255269
---
256270

@@ -262,6 +276,7 @@
262276

263277
- **autoStop** (boolean) _(optional)_: Determines if the trace recording should be automatically stopped.
264278
- **filePath** (string) _(optional)_: The absolute file path, or a file path relative to the current working directory, to save the raw trace data. For example, trace.json.gz (compressed) or trace.json (uncompressed).
279+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
265280
- **reload** (boolean) _(optional)_: Determines if, once tracing has started, the current selected page should be automatically reloaded. Navigate the page to the right URL using the [`navigate_page`](#navigate_page) tool BEFORE starting the trace if reload or autoStop is set to true.
266281

267282
---
@@ -273,6 +288,7 @@
273288
**Parameters:**
274289

275290
- **filePath** (string) _(optional)_: The absolute file path, or a file path relative to the current working directory, to save the raw trace data. For example, trace.json.gz (compressed) or trace.json (uncompressed).
291+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
276292

277293
---
278294

@@ -283,6 +299,7 @@
283299
**Parameters:**
284300

285301
- **filePath** (string) **(required)**: A path to a .heapsnapshot file to save the heapsnapshot to.
302+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
286303

287304
---
288305

@@ -294,6 +311,7 @@
294311

295312
**Parameters:**
296313

314+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
297315
- **reqid** (number) _(optional)_: The reqid of the network request. If omitted returns the currently selected request in the DevTools Network panel.
298316
- **requestFilePath** (string) _(optional)_: The absolute or relative path to save the request body to. If omitted, the body is returned inline.
299317
- **responseFilePath** (string) _(optional)_: The absolute or relative path to save the response body to. If omitted, the body is returned inline.
@@ -307,6 +325,7 @@
307325
**Parameters:**
308326

309327
- **includePreservedRequests** (boolean) _(optional)_: Set to true to return the preserved requests over the last 3 navigations.
328+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
310329
- **pageIdx** (integer) _(optional)_: Page number to return (0-based). When omitted, returns the first page.
311330
- **pageSize** (integer) _(optional)_: Maximum number of requests to return. When omitted, returns all requests.
312331
- **resourceTypes** (array) _(optional)_: Filter requests to only return requests of the specified resource types. When omitted or empty, returns all requests.
@@ -333,6 +352,7 @@ so returned values have to be JSON-serializable.
333352
}`
334353

335354
- **args** (array) _(optional)_: An optional list of arguments to pass to the function.
355+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
336356

337357
---
338358

@@ -343,6 +363,7 @@ so returned values have to be JSON-serializable.
343363
**Parameters:**
344364

345365
- **msgid** (number) **(required)**: The msgid of a console message on the page from the listed console messages
366+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
346367

347368
---
348369

@@ -355,6 +376,7 @@ so returned values have to be JSON-serializable.
355376
- **device** (enum: "desktop", "mobile") _(optional)_: Device to [`emulate`](#emulate).
356377
- **mode** (enum: "navigation", "snapshot") _(optional)_: "navigation" reloads &amp; audits. "snapshot" analyzes current state.
357378
- **outputDirPath** (string) _(optional)_: Directory for reports. If omitted, uses temporary files.
379+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
358380

359381
---
360382

@@ -365,6 +387,7 @@ so returned values have to be JSON-serializable.
365387
**Parameters:**
366388

367389
- **includePreservedMessages** (boolean) _(optional)_: Set to true to return the preserved messages over the last 3 navigations.
390+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
368391
- **pageIdx** (integer) _(optional)_: Page number to return (0-based). When omitted, returns the first page.
369392
- **pageSize** (integer) _(optional)_: Maximum number of messages to return. When omitted, returns all requests.
370393
- **types** (array) _(optional)_: Filter messages to only return messages of the specified resource types. When omitted or empty, returns all messages.
@@ -380,6 +403,7 @@ so returned values have to be JSON-serializable.
380403
- **filePath** (string) _(optional)_: The absolute path, or a path relative to the current working directory, to save the screenshot to instead of attaching it to the response.
381404
- **format** (enum: "png", "jpeg", "webp") _(optional)_: Type of format to save the screenshot as. Default is "png"
382405
- **fullPage** (boolean) _(optional)_: If set to true takes a screenshot of the full page instead of the currently visible viewport. Incompatible with uid.
406+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
383407
- **quality** (number) _(optional)_: Compression quality for JPEG and WebP formats (0-100). Higher values mean better quality but larger file sizes. Ignored for PNG format.
384408
- **uid** (string) _(optional)_: The uid of an element on the page from the page content snapshot. If omitted takes a pages screenshot.
385409

@@ -394,6 +418,7 @@ in the DevTools Elements panel (if any).
394418
**Parameters:**
395419

396420
- **filePath** (string) _(optional)_: The absolute path, or a path relative to the current working directory, to save the snapshot to instead of attaching it to the response.
421+
- **pageId** (number) _(optional)_: Targets a specific page by ID. Use [`list_pages`](#list_pages) to get available page IDs. If omitted, operates on the most recently selected page.
397422
- **verbose** (boolean) _(optional)_: Whether to include all possible information available in the full a11y tree. Default is false.
398423

399424
---

scripts/generate-docs.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {get_encoding} from 'tiktoken';
1414
import {cliOptions} from '../build/src/bin/chrome-devtools-mcp-cli-options.js';
1515
import type {ParsedArguments} from '../build/src/bin/chrome-devtools-mcp-cli-options.js';
1616
import {ToolCategory, labels} from '../build/src/tools/categories.js';
17+
import {pageIdSchema} from '../build/src/tools/ToolDefinition.js';
1718
import {createTools} from '../build/src/tools/tools.js';
1819

1920
const OUTPUT_PATH = './docs/tool-reference.md';
@@ -432,7 +433,7 @@ async function generateReference(
432433
}
433434

434435
// eslint-disable-next-line @typescript-eslint/no-explicit-any
435-
function getToolsAndCategories(tools: any) {
436+
function getToolsAndCategories(tools: any, slim = false) {
436437
// Convert ToolDefinitions to ToolWithAnnotations
437438
const toolsWithAnnotations: ToolWithAnnotations[] = tools
438439
.filter(tool => {
@@ -447,8 +448,12 @@ function getToolsAndCategories(tools: any) {
447448
const properties: Record<string, TypeInfo> = {};
448449
const required: string[] = [];
449450

451+
const toolSchema = {
452+
...tool.schema,
453+
...(tool.pageScoped && !slim ? pageIdSchema : {}),
454+
};
450455
for (const [key, schema] of Object.entries(
451-
tool.schema as unknown as Record<string, ZodSchema>,
456+
toolSchema as unknown as Record<string, ZodSchema>,
452457
)) {
453458
const info = getZodTypeInfo(schema);
454459
properties[key] = info;
@@ -521,7 +526,10 @@ async function generateToolDocumentation(): Promise<void> {
521526

522527
{
523528
const {toolsWithAnnotations, categories, sortedCategories} =
524-
getToolsAndCategories(createTools({slim: true} as ParsedArguments));
529+
getToolsAndCategories(
530+
createTools({slim: true} as ParsedArguments),
531+
true,
532+
);
525533
await generateReference(
526534
'Chrome DevTools MCP Slim Tool Reference',
527535
SLIM_OUTPUT_PATH,

src/bin/chrome-devtools-mcp-cli-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export const cliOptions = {
150150
experimentalPageIdRouting: {
151151
type: 'boolean',
152152
describe:
153-
'Whether to expose pageId on page-scoped tools and route requests by page ID.',
153+
'(Deprecated, now always enabled) pageId is always exposed on page-scoped tools.',
154154
hidden: true,
155155
},
156156
experimentalDevtools: {

0 commit comments

Comments
 (0)