chrome-devtools-mcp 1.4.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +20 -3
  2. package/build/src/HeapSnapshotManager.js +83 -16
  3. package/build/src/McpContext.js +218 -367
  4. package/build/src/McpPage.js +242 -31
  5. package/build/src/McpResponse.js +165 -60
  6. package/build/src/PageCollector.js +48 -122
  7. package/build/src/TextSnapshot.js +20 -2
  8. package/build/src/ToolHandler.js +13 -3
  9. package/build/src/WaitForHelper.js +18 -8
  10. package/build/src/bin/chrome-devtools-cli-options.js +76 -4
  11. package/build/src/bin/chrome-devtools-mcp-cli-options.js +15 -6
  12. package/build/src/bin/chrome-devtools-mcp-main.js +2 -2
  13. package/build/src/bin/chrome-devtools.js +25 -1
  14. package/build/src/browser.js +1 -1
  15. package/build/src/daemon/client.js +33 -3
  16. package/build/src/daemon/daemon.js +3 -2
  17. package/build/src/daemon/utils.js +1 -1
  18. package/build/src/devtools/DevtoolsUtils.js +2 -63
  19. package/build/src/{issue-descriptions.js → devtools/issueDescriptions.js} +8 -6
  20. package/build/src/formatters/HeapSnapshotFormatter.js +43 -0
  21. package/build/src/formatters/IssueFormatter.js +2 -2
  22. package/build/src/index.js +14 -5
  23. package/build/src/telemetry/ClearcutLogger.js +1 -1
  24. package/build/src/telemetry/WatchdogClient.js +1 -1
  25. package/build/src/telemetry/metricsRegistry.js +2 -9
  26. package/build/src/telemetry/persistence.js +1 -1
  27. package/build/src/telemetry/transformation.js +20 -0
  28. package/build/src/telemetry/watchdog/ClearcutSender.js +1 -1
  29. package/build/src/telemetry/watchdog/main.js +1 -1
  30. package/build/src/third_party/THIRD_PARTY_NOTICES +13 -279
  31. package/build/src/third_party/bundled-packages.json +3 -5
  32. package/build/src/third_party/devtools-heap-snapshot-worker.js +81 -0
  33. package/build/src/third_party/index.js +2418 -2197
  34. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +3082 -6343
  35. package/build/src/tools/emulation.js +2 -2
  36. package/build/src/tools/extensions.js +1 -1
  37. package/build/src/tools/input.js +17 -8
  38. package/build/src/tools/lighthouse.js +1 -1
  39. package/build/src/tools/memory.js +76 -6
  40. package/build/src/tools/network.js +4 -4
  41. package/build/src/tools/pages.js +21 -89
  42. package/build/src/tools/performance.js +2 -2
  43. package/build/src/tools/screencast.js +1 -2
  44. package/build/src/tools/script.js +6 -10
  45. package/build/src/tools/snapshot.js +2 -2
  46. package/build/src/tools/thirdPartyDeveloper.js +7 -7
  47. package/build/src/tools/webmcp.js +1 -1
  48. package/build/src/trace-processing/parse.js +1 -1
  49. package/build/src/utils/files.js +0 -4
  50. package/build/src/{logger.js → utils/logger.js} +1 -1
  51. package/build/src/{polyfill.js → utils/polyfill.js} +1 -1
  52. package/build/src/version.js +1 -1
  53. package/package.json +17 -5
  54. package/skills/memory-leak-debugging/SKILL.md +22 -14
  55. package/build/src/utils/types.js +0 -7
  56. /package/build/src/{Mutex.js → utils/Mutex.js} +0 -0
@@ -4,9 +4,9 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { FakeIssuesManager } from './devtools/DevtoolsUtils.js';
7
- import { logger } from './logger.js';
8
7
  import { DevTools } from './third_party/index.js';
9
8
  import { createIdGenerator, stableIdSymbol, } from './utils/id.js';
9
+ import { logger } from './utils/logger.js';
10
10
  export class UncaughtError {
11
11
  details;
12
12
  targetId;
@@ -16,113 +16,55 @@ export class UncaughtError {
16
16
  }
17
17
  }
18
18
  export class PageCollector {
19
- #browser;
20
- #listenersInitializer;
21
- #listeners = new WeakMap();
19
+ pptrPage;
20
+ #listeners;
22
21
  maxNavigationSaved = 3;
23
22
  /**
24
23
  * This maps a Page to a list of navigations with a sub-list
25
24
  * of all collected resources.
26
25
  * The newer navigations come first.
27
26
  */
28
- storage = new WeakMap();
29
- constructor(browser, listeners) {
30
- this.#browser = browser;
31
- this.#listenersInitializer = listeners;
32
- }
33
- async init(pages) {
34
- for (const page of pages) {
35
- this.addPage(page);
36
- }
37
- this.#browser.on('targetcreated', this.#onTargetCreated);
38
- this.#browser.on('targetdestroyed', this.#onTargetDestroyed);
39
- }
40
- dispose() {
41
- this.#browser.off('targetcreated', this.#onTargetCreated);
42
- this.#browser.off('targetdestroyed', this.#onTargetDestroyed);
43
- }
44
- #onTargetCreated = async (target) => {
45
- try {
46
- const page = await target.page();
47
- if (!page) {
48
- return;
49
- }
50
- this.addPage(page);
51
- }
52
- catch (err) {
53
- logger?.('Error getting a page for a target onTargetCreated', err);
54
- }
55
- };
56
- #onTargetDestroyed = async (target) => {
57
- try {
58
- const page = await target.page();
59
- if (!page) {
60
- return;
61
- }
62
- this.cleanupPageDestroyed(page);
63
- }
64
- catch (err) {
65
- logger?.('Error getting a page for a target onTargetDestroyed', err);
66
- }
67
- };
68
- addPage(page) {
69
- this.#initializePage(page);
70
- }
71
- #initializePage(page) {
72
- if (this.storage.has(page)) {
73
- return;
74
- }
27
+ storage = [[]];
28
+ constructor(page, listeners) {
29
+ this.pptrPage = page;
75
30
  const idGenerator = createIdGenerator();
76
- const storedLists = [[]];
77
- this.storage.set(page, storedLists);
78
- const listeners = this.#listenersInitializer(value => {
31
+ const listenerMap = listeners(value => {
79
32
  const withId = value;
80
33
  withId[stableIdSymbol] = idGenerator();
81
- const navigations = this.storage.get(page) ?? [[]];
82
- navigations[0].push(withId);
34
+ this.storage[0].push(withId);
83
35
  });
84
- listeners['framenavigated'] = (frame) => {
36
+ listenerMap['framenavigated'] = (frame) => {
85
37
  // Only split the storage on main frame navigation
86
- if (frame !== page.mainFrame()) {
38
+ if (frame !== this.pptrPage.mainFrame()) {
87
39
  return;
88
40
  }
89
- this.splitAfterNavigation(page);
41
+ this.splitAfterNavigation();
90
42
  };
91
- for (const [name, listener] of Object.entries(listeners)) {
92
- page.on(name, listener);
43
+ for (const [name, listener] of Object.entries(listenerMap)) {
44
+ this.pptrPage.on(name, listener);
93
45
  }
94
- this.#listeners.set(page, listeners);
46
+ this.#listeners = listenerMap;
95
47
  }
96
- splitAfterNavigation(page) {
97
- const navigations = this.storage.get(page);
98
- if (!navigations) {
99
- return;
100
- }
101
- // Add the latest navigation first
102
- navigations.unshift([]);
103
- navigations.splice(this.maxNavigationSaved);
104
- }
105
- cleanupPageDestroyed(page) {
106
- const listeners = this.#listeners.get(page);
107
- if (listeners) {
108
- for (const [name, listener] of Object.entries(listeners)) {
109
- page.off(name, listener);
48
+ dispose() {
49
+ if (this.#listeners) {
50
+ for (const [name, listener] of Object.entries(this.#listeners)) {
51
+ this.pptrPage.off(name, listener);
110
52
  }
111
53
  }
112
- this.storage.delete(page);
113
54
  }
114
- getData(page, includePreservedData) {
115
- const navigations = this.storage.get(page);
116
- if (!navigations) {
117
- return [];
118
- }
55
+ splitAfterNavigation() {
56
+ // Add the latest navigation first
57
+ this.storage.unshift([]);
58
+ this.storage.splice(this.maxNavigationSaved);
59
+ }
60
+ getData(includePreservedData) {
119
61
  if (!includePreservedData) {
120
- return navigations[0];
62
+ return this.storage[0];
121
63
  }
122
64
  const data = [];
123
65
  for (let index = this.maxNavigationSaved; index >= 0; index--) {
124
- if (navigations[index]) {
125
- data.push(...navigations[index]);
66
+ if (this.storage[index]) {
67
+ data.push(...this.storage[index]);
126
68
  }
127
69
  }
128
70
  return data;
@@ -130,23 +72,15 @@ export class PageCollector {
130
72
  getIdForResource(resource) {
131
73
  return resource[stableIdSymbol] ?? -1;
132
74
  }
133
- getById(page, stableId) {
134
- const navigations = this.storage.get(page);
135
- if (!navigations) {
136
- throw new Error('No requests found for selected page');
137
- }
138
- const item = this.find(page, item => item[stableIdSymbol] === stableId);
75
+ getById(stableId) {
76
+ const item = this.find(item => item[stableIdSymbol] === stableId);
139
77
  if (!item) {
140
78
  throw new Error('Request not found for selected page');
141
79
  }
142
80
  return item;
143
81
  }
144
- find(page, filter) {
145
- const navigations = this.storage.get(page);
146
- if (!navigations) {
147
- return;
148
- }
149
- for (const navigation of navigations) {
82
+ find(filter) {
83
+ for (const navigation of this.storage) {
150
84
  const item = navigation.find(filter);
151
85
  if (item) {
152
86
  return item;
@@ -156,19 +90,15 @@ export class PageCollector {
156
90
  }
157
91
  }
158
92
  export class ConsoleCollector extends PageCollector {
159
- #subscribedPages = new WeakMap();
160
- addPage(page) {
161
- super.addPage(page);
162
- if (!this.#subscribedPages.has(page)) {
163
- const subscriber = new PageEventSubscriber(page);
164
- this.#subscribedPages.set(page, subscriber);
165
- void subscriber.subscribe();
166
- }
93
+ #subscriber;
94
+ constructor(page, listeners) {
95
+ super(page, listeners);
96
+ this.#subscriber = new PageEventSubscriber(this.pptrPage);
97
+ this.#subscriber.subscribe();
167
98
  }
168
- cleanupPageDestroyed(page) {
169
- super.cleanupPageDestroyed(page);
170
- this.#subscribedPages.get(page)?.unsubscribe();
171
- this.#subscribedPages.delete(page);
99
+ dispose() {
100
+ super.dispose();
101
+ this.#subscriber?.unsubscribe();
172
102
  }
173
103
  }
174
104
  class PageEventSubscriber {
@@ -194,7 +124,7 @@ class PageEventSubscriber {
194
124
  this.#issueAggregator = new DevTools.IssueAggregator(this.#issueManager);
195
125
  this.#issueAggregator.addEventListener("AggregatedIssueUpdated" /* DevTools.IssueAggregatorEvents.AGGREGATED_ISSUE_UPDATED */, this.#onAggregatedIssue);
196
126
  }
197
- async subscribe() {
127
+ subscribe() {
198
128
  this.#resetIssueAggregator();
199
129
  this.#page.on('framenavigated', this.#onFrameNavigated);
200
130
  this.#page.on('issue', this.#onIssueAdded);
@@ -261,23 +191,19 @@ class PageEventSubscriber {
261
191
  };
262
192
  }
263
193
  export class NetworkCollector extends PageCollector {
264
- constructor(browser, listeners = collect => {
194
+ constructor(page, listeners = collect => {
265
195
  return {
266
196
  request: req => {
267
197
  collect(req);
268
198
  },
269
199
  };
270
200
  }) {
271
- super(browser, listeners);
201
+ super(page, listeners);
272
202
  }
273
- splitAfterNavigation(page) {
274
- const navigations = this.storage.get(page) ?? [];
275
- if (!navigations) {
276
- return;
277
- }
278
- const requests = navigations[0];
203
+ splitAfterNavigation() {
204
+ const requests = this.storage[0];
279
205
  const lastRequestIdx = requests.findLastIndex(request => {
280
- return request.frame() === page.mainFrame()
206
+ return request.frame() === this.pptrPage.mainFrame()
281
207
  ? request.isNavigationRequest()
282
208
  : false;
283
209
  });
@@ -286,12 +212,12 @@ export class NetworkCollector extends PageCollector {
286
212
  // Keep the reference
287
213
  if (lastRequestIdx !== -1) {
288
214
  const fromCurrentNavigation = requests.splice(lastRequestIdx);
289
- navigations.unshift(fromCurrentNavigation);
215
+ this.storage.unshift(fromCurrentNavigation);
290
216
  }
291
217
  else {
292
- navigations.unshift([]);
218
+ this.storage.unshift([]);
293
219
  }
294
- navigations.splice(this.maxNavigationSaved);
220
+ this.storage.splice(this.maxNavigationSaved);
295
221
  }
296
222
  }
297
223
  //# sourceMappingURL=PageCollector.js.map
@@ -3,7 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { logger } from './logger.js';
6
+ import { logger } from './utils/logger.js';
7
7
  export class TextSnapshot {
8
8
  static nextSnapshotId = 1;
9
9
  static resetCounter() {
@@ -88,7 +88,7 @@ export class TextSnapshot {
88
88
  const data = options.devtoolsData ?? (await page.getDevToolsData());
89
89
  if (data?.cdpBackendNodeId) {
90
90
  snapshot.hasSelectedElement = true;
91
- snapshot.selectedElementUid = page.resolveCdpElementId(data.cdpBackendNodeId);
91
+ snapshot.selectedElementUid = snapshot.resolveCdpElementId(data.cdpBackendNodeId);
92
92
  }
93
93
  // Clean up unique IDs that we did not see anymore.
94
94
  for (const key of uniqueBackendNodeIdToMcpId.keys()) {
@@ -98,6 +98,24 @@ export class TextSnapshot {
98
98
  }
99
99
  return snapshot;
100
100
  }
101
+ resolveCdpElementId(cdpBackendNodeId) {
102
+ if (!cdpBackendNodeId) {
103
+ logger?.('no cdpBackendNodeId');
104
+ return;
105
+ }
106
+ // TODO: index by backendNodeId instead.
107
+ const queue = [this.root];
108
+ while (queue.length) {
109
+ const current = queue.pop();
110
+ if (current.backendNodeId === cdpBackendNodeId) {
111
+ return current.id;
112
+ }
113
+ for (const child of current.children) {
114
+ queue.push(child);
115
+ }
116
+ }
117
+ return;
118
+ }
101
119
  // ExtraHandles represent DOM nodes which might not be part of the accessibility tree, e.g. DOM nodes
102
120
  // returned by third-party developer tools. We insert them into the tree by finding the closest ancestor
103
121
  // in the tree and inserting the node as a child. The ancestor's child nodes are re-parented if necessary.
@@ -3,7 +3,6 @@
3
3
  * Copyright 2026 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { logger } from './logger.js';
7
6
  import { McpResponse } from './McpResponse.js';
8
7
  import { SlimMcpResponse } from './SlimMcpResponse.js';
9
8
  import { ClearcutLogger } from './telemetry/ClearcutLogger.js';
@@ -11,6 +10,7 @@ import { bucketizeLatency } from './telemetry/transformation.js';
11
10
  import { zod } from './third_party/index.js';
12
11
  import { labels, OFF_BY_DEFAULT_CATEGORIES } from './tools/categories.js';
13
12
  import { pageIdSchema } from './tools/ToolDefinition.js';
13
+ import { logger } from './utils/logger.js';
14
14
  export function buildFlag(category) {
15
15
  return `category${category.charAt(0).toUpperCase() + category.slice(1)}`;
16
16
  }
@@ -142,11 +142,13 @@ export class ToolHandler {
142
142
  logger?.(`${this.tool.name} request: ${JSON.stringify(params, null, ' ')}`);
143
143
  const context = await this.getContext();
144
144
  logger?.(`${this.tool.name} context: resolved`);
145
- await context.detectOpenDevToolsWindows();
146
145
  const response = this.serverArgs.slim
147
146
  ? new SlimMcpResponse(this.serverArgs)
148
147
  : new McpResponse(this.serverArgs);
149
148
  response.setRedactNetworkHeaders(this.serverArgs.redactNetworkHeaders);
149
+ if (context.consumeReconnectNotice()) {
150
+ response.setReconnectNotice();
151
+ }
150
152
  try {
151
153
  if (this.tool.verifyFilesSchema) {
152
154
  for (const key of this.tool.verifyFilesSchema) {
@@ -179,7 +181,15 @@ export class ToolHandler {
179
181
  catch (err) {
180
182
  response.setError(err);
181
183
  }
182
- const { content, structuredContent } = await response.handle(this.tool.name, context, this.serverArgs.experimentalToonFormat ?? false);
184
+ // Resolve data format: --experimentalDataFormat takes precedence, fall back to legacy --experimentalToonFormat
185
+ let dataFormat = 'default';
186
+ if (this.serverArgs.experimentalDataFormat) {
187
+ dataFormat = this.serverArgs.experimentalDataFormat;
188
+ }
189
+ else if (this.serverArgs.experimentalToonFormat) {
190
+ dataFormat = 'toon';
191
+ }
192
+ const { content, structuredContent } = await response.handle(this.tool.name, context, dataFormat);
183
193
  const result = {
184
194
  content,
185
195
  };
@@ -3,7 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import { logger } from './logger.js';
6
+ import { logger } from './utils/logger.js';
7
7
  export class WaitForHelper {
8
8
  #abortController = new AbortController();
9
9
  #page;
@@ -112,15 +112,24 @@ export class WaitForHelper {
112
112
  }
113
113
  if (options?.handleDialog) {
114
114
  const dialogHandler = (dialog) => {
115
- this.#dialogOpened = true;
116
- if (options.handleDialog === 'dismiss') {
117
- void dialog.dismiss();
118
- }
119
- else if (options.handleDialog === 'accept') {
120
- void dialog.accept();
115
+ let actionToTake;
116
+ if (typeof options.handleDialog === 'object') {
117
+ actionToTake = options.handleDialog[dialog.type()];
121
118
  }
122
119
  else {
123
- void dialog.accept(options.handleDialog);
120
+ actionToTake = options.handleDialog;
121
+ }
122
+ if (actionToTake) {
123
+ this.#dialogOpened = true;
124
+ if (actionToTake === 'dismiss') {
125
+ void dialog.dismiss();
126
+ }
127
+ else if (actionToTake === 'accept') {
128
+ void dialog.accept();
129
+ }
130
+ else {
131
+ void dialog.accept(actionToTake);
132
+ }
124
133
  }
125
134
  };
126
135
  this.#page.on('dialog', dialogHandler);
@@ -170,6 +179,7 @@ export class WaitForHelper {
170
179
  ...(urlAfterAction !== this.#initialUrl
171
180
  ? { navigatedToUrl: urlAfterAction }
172
181
  : {}),
182
+ dialogHandled: this.#dialogOpened,
173
183
  };
174
184
  }
175
185
  }
@@ -82,6 +82,30 @@ export const commands = {
82
82
  },
83
83
  },
84
84
  },
85
+ compare_heapsnapshots: {
86
+ description: 'Loads two memory heapsnapshots and returns the comparison. If classIndex is provided, returns detailed diff for that class, otherwise returns summary diff. (requires flag: --memoryDebugging=true)',
87
+ category: 'Memory',
88
+ args: {
89
+ baseFilePath: {
90
+ name: 'baseFilePath',
91
+ type: 'string',
92
+ description: 'A path to the base .heapsnapshot file (earlier snapshot).',
93
+ required: true,
94
+ },
95
+ currentFilePath: {
96
+ name: 'currentFilePath',
97
+ type: 'string',
98
+ description: 'A path to the current .heapsnapshot file (later snapshot).',
99
+ required: true,
100
+ },
101
+ classIndex: {
102
+ name: 'classIndex',
103
+ type: 'number',
104
+ description: 'Optional 0-based index of the class in the summary list to filter results, showing individual objects.',
105
+ required: false,
106
+ },
107
+ },
108
+ },
85
109
  drag: {
86
110
  description: 'Drag an element onto another element',
87
111
  category: 'Input automation',
@@ -157,13 +181,13 @@ export const commands = {
157
181
  },
158
182
  },
159
183
  evaluate_script: {
160
- description: 'Evaluate a JavaScript function inside the currently selected page. Returns the response as JSON,\nso returned values have to be JSON-serializable.',
184
+ description: 'Evaluate a JavaScript function inside the currently selected page. Returns the response as JSON, so returned values have to be JSON-serializable.',
161
185
  category: 'Debugging',
162
186
  args: {
163
187
  function: {
164
188
  name: 'function',
165
189
  type: 'string',
166
- description: 'A JavaScript function declaration to be executed by the tool in the currently selected page.\nExample without arguments: `() => {\n return document.title\n}` or `async () => {\n return await fetch("example.com")\n}`.\nExample with arguments: `(el) => {\n return el.innerText;\n}`\n',
190
+ description: 'A JavaScript function declaration to be executed by the tool in the currently selected page.\nExample without arguments: `() => document.title` or `async () => await fetch("example.com")`.\nExample with arguments: `(el) => el.innerText`\n',
167
191
  required: true,
168
192
  },
169
193
  args: {
@@ -274,6 +298,18 @@ export const commands = {
274
298
  description: 'The ID for the class, obtained from details.',
275
299
  required: true,
276
300
  },
301
+ filterName: {
302
+ name: 'filterName',
303
+ type: 'string',
304
+ description: 'An optional filter to apply to the nodes.',
305
+ required: false,
306
+ enum: [
307
+ 'objectsRetainedByDetachedDomNodes',
308
+ 'objectsRetainedByConsole',
309
+ 'objectsRetainedByEventHandlers',
310
+ 'objectsRetainedByContexts',
311
+ ],
312
+ },
277
313
  pageIdx: {
278
314
  name: 'pageIdx',
279
315
  type: 'number',
@@ -298,6 +334,18 @@ export const commands = {
298
334
  description: 'A path to a .heapsnapshot file to read.',
299
335
  required: true,
300
336
  },
337
+ filterName: {
338
+ name: 'filterName',
339
+ type: 'string',
340
+ description: 'An optional filter to apply to the aggregates.',
341
+ required: false,
342
+ enum: [
343
+ 'objectsRetainedByDetachedDomNodes',
344
+ 'objectsRetainedByConsole',
345
+ 'objectsRetainedByEventHandlers',
346
+ 'objectsRetainedByContexts',
347
+ ],
348
+ },
301
349
  pageIdx: {
302
350
  name: 'pageIdx',
303
351
  type: 'number',
@@ -330,6 +378,30 @@ export const commands = {
330
378
  },
331
379
  },
332
380
  },
381
+ get_heapsnapshot_duplicate_strings: {
382
+ description: 'Loads a memory heapsnapshot and returns duplicate strings grouped by their value. (requires flag: --memoryDebugging=true)',
383
+ category: 'Memory',
384
+ args: {
385
+ filePath: {
386
+ name: 'filePath',
387
+ type: 'string',
388
+ description: 'A path to a .heapsnapshot file to read.',
389
+ required: true,
390
+ },
391
+ pageIdx: {
392
+ name: 'pageIdx',
393
+ type: 'number',
394
+ description: 'The page index for pagination.',
395
+ required: false,
396
+ },
397
+ pageSize: {
398
+ name: 'pageSize',
399
+ type: 'number',
400
+ description: 'The page size for pagination.',
401
+ required: false,
402
+ },
403
+ },
404
+ },
333
405
  get_heapsnapshot_edges: {
334
406
  description: 'Loads a memory heapsnapshot and returns outgoing edges (references) for a specific node ID. (requires flag: --memoryDebugging=true)',
335
407
  category: 'Memory',
@@ -540,7 +612,7 @@ export const commands = {
540
612
  },
541
613
  },
542
614
  list_3p_developer_tools: {
543
- description: "Lists all third-party developer tools the page exposes for providing runtime information.\n Third-party developer tools can be called via the 'execute_3p_developer_tool()' MCP tool.\n Alternatively, third-party developer tools can be executed by calling 'evaluate_script' and adding the\n following command to the script:\n 'window.__dtmcp.executeTool(toolName, params)'\n This might be helpful when the third-party developer tools return non-serializable values or when composing\n third-party developer tools with additional functionality. (requires flag: --categoryExperimentalThirdParty=true)",
615
+ description: "Lists all third-party developer tools the page exposes for providing runtime information.\nThird-party developer tools can be called via the 'execute_3p_developer_tool()' MCP tool.\nAlternatively, third-party developer tools can be executed by calling 'evaluate_script' and adding the\nfollowing command to the script:\n`window.__dtmcp.executeTool(toolName, params)`\nThis might be helpful when the third-party developer tools return non-serializable values or when composing\nthird-party developer tools with additional functionality. (requires flag: --categoryExperimentalThirdParty=true)",
544
616
  category: 'Third-party',
545
617
  args: {},
546
618
  },
@@ -655,7 +727,7 @@ export const commands = {
655
727
  type: 'string',
656
728
  description: 'Whether to auto accept or beforeunload dialogs triggered by this navigation. Default is accept.',
657
729
  required: false,
658
- enum: ['accept', 'decline'],
730
+ enum: ['accept', 'dismiss'],
659
731
  },
660
732
  initScript: {
661
733
  name: 'initScript',
@@ -157,18 +157,19 @@ export const cliOptions = {
157
157
  },
158
158
  experimentalToonFormat: {
159
159
  type: 'boolean',
160
- describe: 'Whether to format structured data in text response using Token-Oriented Object Notation. Defaults to false which represents the embedded content as formatted JSON instead.',
160
+ describe: 'Deprecated: use --experimentalDataFormat=toon instead. Whether to format structured data using TOON (requires @toon-format/toon).',
161
+ hidden: true,
162
+ },
163
+ experimentalDataFormat: {
164
+ type: 'string',
165
+ describe: 'Override format for structured data in text responses. Default uses built-in formatters. "toon" (requires @toon-format/toon) or "gcf" (requires @blackwell-systems/gcf) replace structured content with the specified encoding.',
166
+ choices: ['default', 'toon', 'gcf'],
161
167
  hidden: true,
162
168
  },
163
169
  experimentalIncludeAllPages: {
164
170
  type: 'boolean',
165
171
  describe: 'Whether to include all kinds of pages such as webviews or background pages as pages.',
166
172
  },
167
- experimentalNavigationAllowlist: {
168
- type: 'boolean',
169
- describe: 'Whether to enable navigation allowlist tool parameter.',
170
- hidden: true,
171
- },
172
173
  experimentalInteropTools: {
173
174
  type: 'boolean',
174
175
  describe: 'Whether to enable interoperability tools',
@@ -314,6 +315,14 @@ export const cliOptions = {
314
315
  describe: 'If true, redacts some of the network headers considered sensitive before returning to the client.',
315
316
  default: false,
316
317
  },
318
+ allowUnrestrictedPaths: {
319
+ type: 'boolean',
320
+ default: false,
321
+ describe: 'If set, disables the default path restriction that applies when the MCP client does not negotiate ' +
322
+ 'the roots capability. By default, file-writing tools are restricted to the OS temp directory when ' +
323
+ 'no roots are configured. Use this only when connecting a trusted local client that does not implement ' +
324
+ 'MCP roots and requires access to paths outside the temp directory.',
325
+ },
317
326
  };
318
327
  export function parseArguments(version, argv = process.argv, env = process.env) {
319
328
  const yargsInstance = yargs(hideBin(argv))
@@ -3,15 +3,15 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- import '../polyfill.js';
6
+ import '../utils/polyfill.js';
7
7
  import process from 'node:process';
8
8
  import { closeBrowser } from '../browser.js';
9
9
  import { createMcpServer, logDisclaimers } from '../index.js';
10
- import { logger, saveLogsToFile } from '../logger.js';
11
10
  import { ClearcutLogger } from '../telemetry/ClearcutLogger.js';
12
11
  import { computeFlagUsage } from '../telemetry/flagUtils.js';
13
12
  import { StdioServerTransport } from '../third_party/index.js';
14
13
  import { checkForUpdates } from '../utils/check-for-updates.js';
14
+ import { logger, saveLogsToFile } from '../utils/logger.js';
15
15
  import { VERSION } from '../version.js';
16
16
  import { cliOptions, parseArguments } from './chrome-devtools-mcp-cli-options.js';
17
17
  await checkForUpdates('Run `npm install chrome-devtools-mcp@latest` to update.');
@@ -41,6 +41,7 @@ startCliOptions.isolated.description =
41
41
  'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to true unless userDataDir is provided.';
42
42
  startCliOptions.categoryExtensions.default = true;
43
43
  const y = yargs(hideBin(process.argv))
44
+ .locale('en') // Force English to ensure error string matching works in .fail, all custom messages we output are in English anyways
44
45
  .scriptName('chrome-devtools')
45
46
  .showHelpOnFail(true)
46
47
  .usage('chrome-devtools <command> [...args] --flags')
@@ -55,7 +56,30 @@ const y = yargs(hideBin(process.argv))
55
56
  .version(VERSION)
56
57
  .strict()
57
58
  .help(true)
58
- .wrap(120);
59
+ .wrap(120)
60
+ .fail((msg, err) => {
61
+ if (msg) {
62
+ console.error('Error:', msg);
63
+ if (msg.includes('Not enough non-option arguments') ||
64
+ msg.includes('Unknown argument') ||
65
+ msg.includes('Unknown arguments')) {
66
+ console.error('\n=========================================');
67
+ console.error('💡 TIP FOR AI AGENT / DEVELOPER:');
68
+ console.error('In the `chrome-devtools` CLI:');
69
+ console.error('1. Required parameters MUST be passed as positional arguments (without flags).');
70
+ console.error(' - INCORRECT: chrome-devtools evaluate_script --expression "() => document.title"');
71
+ console.error(' - CORRECT: chrome-devtools evaluate_script "() => document.title"');
72
+ console.error('2. Optional parameters are passed as double-dash options/flags (e.g. --pageId 1).');
73
+ console.error('3. Make sure to escape quotes properly for your shell environment.');
74
+ console.error('Run `chrome-devtools <command> --help` to see exact positional and optional parameters.');
75
+ console.error('=========================================');
76
+ }
77
+ }
78
+ else if (err) {
79
+ console.error(err);
80
+ }
81
+ process.exit(1);
82
+ });
59
83
  y.command('start', 'Start or restart chrome-devtools-mcp', y => y
60
84
  .options(startCliOptions)
61
85
  .example('$0 start --browserUrl http://localhost:9222', 'Start the server connecting to an existing browser')
@@ -7,8 +7,8 @@ import { execSync } from 'node:child_process';
7
7
  import fs from 'node:fs';
8
8
  import os from 'node:os';
9
9
  import path from 'node:path';
10
- import { logger } from './logger.js';
11
10
  import { puppeteer } from './third_party/index.js';
11
+ import { logger } from './utils/logger.js';
12
12
  let browser;
13
13
  let browserMode;
14
14
  function makeTargetFilter(enableExtensions = false) {