chrome-devtools-mcp 1.10.1 → 1.12.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 (103) hide show
  1. package/README.md +72 -20
  2. package/build/src/BrowserManager.js +155 -27
  3. package/build/src/McpContext.js +598 -200
  4. package/build/src/McpPage.js +513 -131
  5. package/build/src/McpResponse.js +291 -116
  6. package/build/src/McpWorker.js +66 -0
  7. package/build/src/SlimMcpResponse.js +5 -1
  8. package/build/src/TextSnapshot.js +40 -20
  9. package/build/src/ToolHandler.js +306 -147
  10. package/build/src/bin/chrome-devtools-mcp-main.js +13 -10
  11. package/build/src/bin/chrome-devtools-mcp.js +1 -1
  12. package/build/src/bin/chrome-devtools.js +34 -44
  13. package/build/src/collectors/PageCollector.js +13 -9
  14. package/build/src/collectors/ServiceWorkerCollector.js +20 -13
  15. package/build/src/collectors/constants.js +7 -0
  16. package/build/src/config/ConfigLocator.js +70 -0
  17. package/build/src/config/ConfigParser.js +159 -0
  18. package/build/src/config/ConfigWatcher.js +94 -0
  19. package/build/src/config/ServerConfig.js +251 -0
  20. package/build/src/config/browser-options.js +15 -17
  21. package/build/src/config/category-options.js +15 -30
  22. package/build/src/config/cli-commands.js +165 -5
  23. package/build/src/config/cli-options.js +441 -58
  24. package/build/src/config/mcp-options.js +212 -264
  25. package/build/src/config/puppeteer-options.js +67 -0
  26. package/build/src/config/tool-options.js +60 -0
  27. package/build/src/daemon/client.js +84 -44
  28. package/build/src/daemon/daemon.js +59 -45
  29. package/build/src/daemon/utils.js +46 -12
  30. package/build/src/devtools/DevToolsCommentBridge.js +71 -11
  31. package/build/src/devtools/DevtoolsUtils.js +52 -15
  32. package/build/src/devtools/McpHostBindingAdapter.js +0 -1
  33. package/build/src/formatters/CommentFormatter.js +4 -13
  34. package/build/src/formatters/ConsoleFormatter.js +29 -2
  35. package/build/src/formatters/CssFormatter.js +3 -2
  36. package/build/src/formatters/HeapSnapshotFormatter.js +111 -57
  37. package/build/src/formatters/IssueFormatter.js +33 -32
  38. package/build/src/formatters/NetworkFormatter.js +62 -22
  39. package/build/src/formatters/RemoteObjectFormatter.js +231 -0
  40. package/build/src/formatters/SnapshotFormatter.js +44 -7
  41. package/build/src/index.js +285 -88
  42. package/build/src/processors/ChunkedTraceParser.js +11 -11
  43. package/build/src/processors/HeapSnapshotManager.js +455 -156
  44. package/build/src/processors/PerformanceTrace.js +9 -9
  45. package/build/src/telemetry/ClearcutLogger.js +1 -1
  46. package/build/src/telemetry/transformation.js +7 -11
  47. package/build/src/telemetry/watchdog/main.js +1 -1
  48. package/build/src/third_party/THIRD_PARTY_NOTICES +399 -689
  49. package/build/src/third_party/bundled-packages.json +7 -8
  50. package/build/src/third_party/cli.js +9239 -0
  51. package/build/src/third_party/devtools-formatter-worker.js +4299 -2517
  52. package/build/src/third_party/devtools-heap-snapshot-worker.js +1298 -22
  53. package/build/src/third_party/index.js +132003 -146852
  54. package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantRead.md +0 -1
  55. package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantReadOptOut.md +5 -0
  56. package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSet.md +0 -1
  57. package/build/src/third_party/issue-descriptions/cookieWarnMetadataGrantSetOptOut.md +5 -0
  58. package/build/src/third_party/issue-descriptions/deprecation.md +1 -1
  59. package/build/src/third_party/issue-descriptions/genericGeolocationPromptWithoutUserGesture.md +5 -0
  60. package/build/src/third_party/issue-descriptions/sriValidationFailedIntegrityMismatch.md +2 -0
  61. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
  62. package/build/src/tools/ToolDefinition.js +102 -12
  63. package/build/src/tools/comments.js +62 -4
  64. package/build/src/tools/console.js +6 -4
  65. package/build/src/tools/css.js +5 -2
  66. package/build/src/tools/emulation.js +22 -8
  67. package/build/src/tools/extensions.js +5 -0
  68. package/build/src/tools/input.js +29 -9
  69. package/build/src/tools/lighthouse.js +136 -12
  70. package/build/src/tools/memory.js +166 -59
  71. package/build/src/tools/network.js +5 -4
  72. package/build/src/tools/pages.js +52 -7
  73. package/build/src/tools/performance.js +28 -7
  74. package/build/src/tools/pwa.js +7 -0
  75. package/build/src/tools/screencast.js +74 -33
  76. package/build/src/tools/screenshot.js +52 -21
  77. package/build/src/tools/script.js +125 -40
  78. package/build/src/tools/slim/tools.js +27 -13
  79. package/build/src/tools/snapshot.js +13 -3
  80. package/build/src/tools/thirdPartyDeveloper.js +9 -5
  81. package/build/src/tools/tools.js +35 -22
  82. package/build/src/tools/webmcp.js +11 -6
  83. package/build/src/types.js +11 -0
  84. package/build/src/utils/TaskRunner.js +136 -0
  85. package/build/src/utils/WaitForHelper.js +15 -2
  86. package/build/src/utils/bytes.js +2 -12
  87. package/build/src/utils/check-for-updates.js +2 -2
  88. package/build/src/utils/disclaimers.js +27 -0
  89. package/build/src/utils/errorHandling.js +20 -0
  90. package/build/src/utils/keyboard.js +14 -2
  91. package/build/src/utils/logger.js +84 -5
  92. package/build/src/utils/resourceType.js +27 -0
  93. package/build/src/utils/text.js +44 -0
  94. package/build/src/utils/timeout.js +14 -0
  95. package/build/src/utils/url.js +140 -3
  96. package/build/src/version.js +1 -1
  97. package/package.json +16 -11
  98. package/skills/a11y-debugging/SKILL.md +7 -12
  99. package/skills/chrome-devtools/SKILL.md +2 -2
  100. package/skills/chrome-devtools-cli/SKILL.md +18 -15
  101. package/skills/cookie-debugging/SKILL.md +8 -5
  102. package/skills/debug-optimize-lcp/SKILL.md +1 -1
  103. package/skills/troubleshooting/SKILL.md +5 -6
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Short id prefix that labels a worker's type in its id, e.g. `sw-1` for a
8
+ * service worker. The numeric part comes from a single shared counter, so the
9
+ * prefix is a readable type tag rather than a per-type sequence.
10
+ */
11
+ const WORKER_ID_PREFIX = {
12
+ service_worker: 'sw',
13
+ dedicated_worker: 'dw',
14
+ shared_worker: 'shw',
15
+ };
16
+ export function workerIdPrefix(type) {
17
+ return WORKER_ID_PREFIX[type];
18
+ }
19
+ // Single shared counter across worker types. Ids are not reused across
20
+ // reconnects, mirroring the page id counter in McpContext; the type prefix is
21
+ // what distinguishes the kinds, not a per-type sequence.
22
+ let nextWorkerId = 1;
23
+ /**
24
+ * Wraps a Puppeteer worker {@link Target}, mirroring {@link McpPage}: it owns the
25
+ * target and the stable id assigned to it and lazily resolves the underlying
26
+ * {@link WebWorker}. Generalizes the former plain `ExtensionServiceWorker` type so
27
+ * dedicated and service workers share a single representation.
28
+ */
29
+ export class McpWorker {
30
+ id;
31
+ type;
32
+ #target;
33
+ constructor(id, type, target) {
34
+ this.id = id;
35
+ this.type = type;
36
+ this.#target = target;
37
+ }
38
+ /**
39
+ * Creates a worker with a freshly minted id derived from its type (e.g.
40
+ * `sw-1`). Keeps id composition in one place so callers only supply the type.
41
+ */
42
+ static create(type, target) {
43
+ return new McpWorker(`${workerIdPrefix(type)}-${nextWorkerId++}`, type, target);
44
+ }
45
+ /**
46
+ * Resets the shared id counter. For tests only, mirroring
47
+ * McpContext.resetPageIdsForTesting().
48
+ */
49
+ static resetIdsForTesting() {
50
+ nextWorkerId = 1;
51
+ }
52
+ get target() {
53
+ return this.#target;
54
+ }
55
+ get url() {
56
+ return this.#target.url();
57
+ }
58
+ /**
59
+ * Resolves the worker's execution context, or `undefined` when the target
60
+ * does not expose one (e.g. it closed before the session attached).
61
+ */
62
+ async worker() {
63
+ return (await this.#target.worker()) ?? undefined;
64
+ }
65
+ }
66
+ //# sourceMappingURL=McpWorker.js.map
@@ -6,9 +6,13 @@
6
6
  import { McpResponse } from './McpResponse.js';
7
7
  export class SlimMcpResponse extends McpResponse {
8
8
  async handle(_context) {
9
+ const error = this.error;
10
+ const responseText = error
11
+ ? [...this.responseLines, `Error: ${error.message}`].join('\n')
12
+ : this.responseLines.join('\n');
9
13
  const text = {
10
14
  type: 'text',
11
- text: this.responseLines.join('\n'),
15
+ text: responseText,
12
16
  };
13
17
  return {
14
18
  content: [text],
@@ -56,6 +56,16 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
56
56
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
57
57
  });
58
58
  import { logger } from './utils/logger.js';
59
+ import { withTimeout } from './utils/timeout.js';
60
+ const ACCESSIBILITY_SNAPSHOT_TIMEOUT_MS = 10_000;
61
+ /**
62
+ * InlineTextBox nodes are layout line fragments of a StaticText node. They
63
+ * repeat the parent text, have no backendNodeId and cannot be targeted by
64
+ * tools. Puppeteer only serializes them for non-interesting-only snapshots.
65
+ */
66
+ function isLayoutOnlyNode(node) {
67
+ return node.role === 'InlineTextBox';
68
+ }
59
69
  export class TextSnapshot {
60
70
  static nextSnapshotId = 1;
61
71
  static resetCounter() {
@@ -77,9 +87,12 @@ export class TextSnapshot {
77
87
  }
78
88
  static async create(page, options = {}) {
79
89
  const verbose = options.verbose ?? false;
80
- const rootNode = await page.pptrPage.accessibility.snapshot({
90
+ const rootNode = await withTimeout(page.pptrPage.accessibility.snapshot({
81
91
  includeIframes: true,
82
92
  interestingOnly: !verbose,
93
+ }), {
94
+ timeout: ACCESSIBILITY_SNAPSHOT_TIMEOUT_MS,
95
+ message: `Timed out after ${ACCESSIBILITY_SNAPSHOT_TIMEOUT_MS}ms waiting for the accessibility tree. The page may have a pending navigation or a crashed renderer. Navigate or reload the page, or select another page.`,
83
96
  });
84
97
  if (!rootNode) {
85
98
  throw new Error('Failed to create accessibility snapshot');
@@ -96,25 +109,29 @@ export class TextSnapshot {
96
109
  let id = '';
97
110
  // @ts-expect-error untyped backendNodeId.
98
111
  const backendNodeId = node.backendNodeId;
99
- // @ts-expect-error untyped loaderId.
100
- const uniqueBackendId = `${node.loaderId}_${backendNodeId}`;
101
- const existingMcpId = uniqueBackendNodeIdToMcpId.get(uniqueBackendId);
102
- if (existingMcpId !== undefined) {
103
- // Re-use MCP exposed ID if the uniqueId is the same.
104
- id = existingMcpId;
105
- }
106
- else {
107
- // Only generate a new ID if we have not seen the node before.
108
- id = `${snapshotId}_${idCounter++}`;
109
- uniqueBackendNodeIdToMcpId.set(uniqueBackendId, id);
112
+ if (backendNodeId !== undefined) {
113
+ // @ts-expect-error untyped loaderId.
114
+ const uniqueBackendId = `${node.loaderId}_${backendNodeId}`;
115
+ const existingMcpId = uniqueBackendNodeIdToMcpId.get(uniqueBackendId);
116
+ if (existingMcpId !== undefined) {
117
+ // Re-use MCP exposed ID if the uniqueId is the same.
118
+ id = existingMcpId;
119
+ }
120
+ else {
121
+ // Only generate a new ID if we have not seen the node before.
122
+ id = `${snapshotId}_${idCounter++}`;
123
+ uniqueBackendNodeIdToMcpId.set(uniqueBackendId, id);
124
+ }
125
+ seenUniqueIds.add(uniqueBackendId);
126
+ seenBackendNodeIds.add(backendNodeId);
110
127
  }
111
- seenUniqueIds.add(uniqueBackendId);
112
- seenBackendNodeIds.add(backendNodeId);
113
128
  const nodeWithId = {
114
129
  ...node,
115
130
  id,
116
131
  children: node.children
117
- ? node.children.map(child => assignIds(child))
132
+ ? node.children
133
+ .filter(child => !isLayoutOnlyNode(child))
134
+ .map(child => assignIds(child))
118
135
  : [],
119
136
  };
120
137
  // The AXNode for an option doesn't contain its `value`.
@@ -125,11 +142,13 @@ export class TextSnapshot {
125
142
  nodeWithId.value = optionText.toString();
126
143
  }
127
144
  }
128
- idToNode.set(nodeWithId.id, nodeWithId);
145
+ if (id) {
146
+ idToNode.set(nodeWithId.id, nodeWithId);
147
+ }
129
148
  return nodeWithId;
130
149
  };
131
150
  const rootNodeWithId = assignIds(rootNode);
132
- await TextSnapshot.insertExtraNodes(page, idToNode, seenUniqueIds, snapshotId, idCounter, rootNodeWithId, seenBackendNodeIds, options.extraHandles ?? []);
151
+ await TextSnapshot.#insertExtraNodes(page, idToNode, seenUniqueIds, snapshotId, idCounter, rootNodeWithId, seenBackendNodeIds, options.extraHandles ?? []);
133
152
  const snapshot = new TextSnapshot({
134
153
  root: rootNodeWithId,
135
154
  snapshotId: String(snapshotId),
@@ -157,21 +176,22 @@ export class TextSnapshot {
157
176
  }
158
177
  // TODO: index by backendNodeId instead.
159
178
  const queue = [this.root];
160
- while (queue.length) {
161
- const current = queue.pop();
179
+ let current = queue.pop();
180
+ while (current) {
162
181
  if (current.backendNodeId === cdpBackendNodeId) {
163
182
  return current.id;
164
183
  }
165
184
  for (const child of current.children) {
166
185
  queue.push(child);
167
186
  }
187
+ current = queue.pop();
168
188
  }
169
189
  return;
170
190
  }
171
191
  // ExtraHandles represent DOM nodes which might not be part of the accessibility tree, e.g. DOM nodes
172
192
  // returned by third-party developer tools. We insert them into the tree by finding the closest ancestor
173
193
  // in the tree and inserting the node as a child. The ancestor's child nodes are re-parented if necessary.
174
- static async insertExtraNodes(page, idToNode, seenUniqueIds, snapshotId, idCounter, rootNodeWithId, seenBackendNodeIds, extraHandles) {
194
+ static async #insertExtraNodes(page, idToNode, seenUniqueIds, snapshotId, idCounter, rootNodeWithId, seenBackendNodeIds, extraHandles) {
175
195
  const { uniqueBackendNodeIdToMcpId } = page;
176
196
  const createExtraNode = async (handle) => {
177
197
  const backendNodeId = await handle.backendNodeId();