chrome-devtools-mcp 1.8.0 → 1.10.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 (72) hide show
  1. package/README.md +20 -908
  2. package/build/src/BrowserManager.js +401 -0
  3. package/build/src/McpContext.js +43 -26
  4. package/build/src/McpPage.js +112 -4
  5. package/build/src/McpResponse.js +68 -3
  6. package/build/src/ToolHandler.js +184 -160
  7. package/build/src/bin/chrome-devtools-mcp-main.js +12 -7
  8. package/build/src/bin/chrome-devtools.js +6 -12
  9. package/build/src/collectors/PageCollector.js +66 -3
  10. package/build/src/config/browser-options.js +125 -0
  11. package/build/src/config/category-options.js +89 -0
  12. package/build/src/config/cli-commands.js +26 -0
  13. package/build/src/config/cli-options.js +34 -2
  14. package/build/src/config/mcp-options.js +86 -147
  15. package/build/src/daemon/utils.js +6 -0
  16. package/build/src/devtools/DevToolsCommentBridge.js +91 -0
  17. package/build/src/devtools/DevtoolsUtils.js +27 -21
  18. package/build/src/formatters/CommentFormatter.js +82 -0
  19. package/build/src/formatters/CssFormatter.js +812 -0
  20. package/build/src/formatters/NetworkFormatter.js +5 -2
  21. package/build/src/index.js +175 -128
  22. package/build/src/processors/ChunkedTraceParser.js +361 -0
  23. package/build/src/processors/PerformanceTrace.js +60 -13
  24. package/build/src/telemetry/ClearcutLogger.js +95 -37
  25. package/build/src/telemetry/metricsRegistry.js +3 -0
  26. package/build/src/telemetry/persistence.js +17 -7
  27. package/build/src/telemetry/transformation.js +53 -4
  28. package/build/src/telemetry/types.js +1 -0
  29. package/build/src/third_party/THIRD_PARTY_NOTICES +687 -133
  30. package/build/src/third_party/bundled-packages.json +6 -3
  31. package/build/src/third_party/devtools-formatter-worker.js +158 -5
  32. package/build/src/third_party/devtools-heap-snapshot-worker.js +589 -6
  33. package/build/src/third_party/index.js +59173 -38013
  34. package/build/src/third_party/issue-descriptions/webInstallManifestMissingId.md +3 -0
  35. package/build/src/third_party/issue-descriptions/webInstallManifestMissingNameOrShortName.md +3 -0
  36. package/build/src/third_party/issue-descriptions/webInstallManifestParsingOrNetworkError.md +3 -0
  37. package/build/src/third_party/issue-descriptions/webInstallNoManifest.md +3 -0
  38. package/build/src/third_party/issue-descriptions/webInstallStartUrlInvalid.md +3 -0
  39. package/build/src/tools/ToolDefinition.js +28 -21
  40. package/build/src/tools/categories.js +0 -6
  41. package/build/src/tools/comments.js +169 -0
  42. package/build/src/tools/console.js +3 -3
  43. package/build/src/tools/css.js +45 -0
  44. package/build/src/tools/emulation.js +5 -5
  45. package/build/src/tools/extensions.js +10 -10
  46. package/build/src/tools/input.js +159 -87
  47. package/build/src/tools/lighthouse.js +18 -7
  48. package/build/src/tools/memory.js +26 -26
  49. package/build/src/tools/network.js +5 -5
  50. package/build/src/tools/pages.js +34 -19
  51. package/build/src/tools/performance.js +7 -6
  52. package/build/src/tools/pwa.js +8 -8
  53. package/build/src/tools/screencast.js +5 -4
  54. package/build/src/tools/screenshot.js +2 -2
  55. package/build/src/tools/script.js +8 -7
  56. package/build/src/tools/slim/tools.js +45 -37
  57. package/build/src/tools/snapshot.js +4 -4
  58. package/build/src/tools/thirdPartyDeveloper.js +4 -4
  59. package/build/src/tools/tools.js +6 -9
  60. package/build/src/tools/webmcp.js +4 -4
  61. package/build/src/types.js +4 -1
  62. package/build/src/utils/WaitForHelper.js +26 -9
  63. package/build/src/utils/logger.js +7 -6
  64. package/build/src/utils/url.js +73 -0
  65. package/build/src/version.js +1 -1
  66. package/package.json +9 -6
  67. package/skills/chrome-devtools/SKILL.md +2 -1
  68. package/skills/chrome-devtools-cli/SKILL.md +3 -7
  69. package/skills/cookie-debugging/SKILL.md +149 -0
  70. package/skills/memory-leak-debugging/SKILL.md +4 -0
  71. package/build/src/browser.js +0 -244
  72. package/build/src/third_party/issue-descriptions/cookieExcludeBlockedWithinRelatedWebsiteSet.md +0 -4
@@ -101,15 +101,18 @@ export function replaceHtmlElementsWithUids(schema) {
101
101
  }
102
102
  }
103
103
  }
104
+ import { DevToolsCommentBridge } from './devtools/DevToolsCommentBridge.js';
104
105
  import { createTargetUniverse, } from './devtools/DevtoolsUtils.js';
105
106
  import { ConsoleCollector, NetworkCollector, } from './collectors/PageCollector.js';
106
107
  import { TextSnapshot } from './TextSnapshot.js';
107
- import { PredefinedNetworkConditions, } from './third_party/index.js';
108
- import { takeSnapshot } from './tools/snapshot.js';
108
+ import { PredefinedNetworkConditions, DevTools, } from './third_party/index.js';
109
109
  const DEFAULT_TIMEOUT = 5_000;
110
110
  const NAVIGATION_TIMEOUT = 10_000;
111
111
  import { logger } from './utils/logger.js';
112
112
  import { getNetworkMultiplierFromString, WaitForHelper, } from './utils/WaitForHelper.js';
113
+ function isBackendNodeId(id) {
114
+ return typeof id === 'number';
115
+ }
113
116
  /**
114
117
  * Per-page state wrapper. Consolidates dialog, snapshot, emulation,
115
118
  * and metadata that were previously scattered across Maps in McpContext.
@@ -139,10 +142,15 @@ export class McpPage {
139
142
  #hasNetworkBlockOrAllowlist;
140
143
  #locatorClass;
141
144
  #navigationTimeout;
145
+ #sourceMaps;
146
+ #commentBridge;
147
+ #onNotification;
142
148
  constructor(page, id, options) {
143
149
  this.#hasNetworkBlockOrAllowlist = options.hasNetworkBlockOrAllowlist;
144
150
  this.#locatorClass = options.locatorClass;
145
151
  this.#navigationTimeout = options.navigationTimeout ?? NAVIGATION_TIMEOUT;
152
+ this.#sourceMaps = options.sourceMaps ?? true;
153
+ this.#onNotification = options.onNotification;
146
154
  this.pptrPage = page;
147
155
  this.id = id;
148
156
  this.isolatedContextName = options.isolatedContextName;
@@ -183,7 +191,9 @@ export class McpPage {
183
191
  }
184
192
  try {
185
193
  const session = await this.pptrPage.createCDPSession();
186
- this.#devtoolsUniverse = await createTargetUniverse(session);
194
+ this.#devtoolsUniverse = await createTargetUniverse(session, {
195
+ sourceMaps: this.#sourceMaps,
196
+ });
187
197
  }
188
198
  catch (e) {
189
199
  logger?.('Failed to initialize DevTools universe', e);
@@ -321,9 +331,29 @@ export class McpPage {
321
331
  }
322
332
  return this.networkCollector.getIdForResource(request);
323
333
  }
334
+ resolveReqidToCdpRequestId(reqid) {
335
+ const request = this.networkCollector.getById(reqid);
336
+ if (!request) {
337
+ return undefined;
338
+ }
339
+ // @ts-expect-error id is internal.
340
+ return request.id;
341
+ }
324
342
  getNetworkRequests(includePreservedRequests) {
325
343
  return this.networkCollector.getData(includePreservedRequests);
326
344
  }
345
+ get commentBridge() {
346
+ return this.#commentBridge;
347
+ }
348
+ async ensureDevToolsCommentBridge(devtoolsPage) {
349
+ if (!this.#commentBridge) {
350
+ this.#commentBridge = new DevToolsCommentBridge({
351
+ onNotification: this.#onNotification,
352
+ });
353
+ }
354
+ await this.#commentBridge.attach(devtoolsPage);
355
+ return this.#commentBridge;
356
+ }
327
357
  async getDevToolsPage() {
328
358
  try {
329
359
  if (await this.pptrPage.hasDevTools()) {
@@ -338,6 +368,11 @@ export class McpPage {
338
368
  return undefined;
339
369
  }
340
370
  }
371
+ async openDevTools() {
372
+ const devtoolsPage = await this.pptrPage.openDevTools();
373
+ await this.ensureDevToolsCommentBridge(devtoolsPage);
374
+ return devtoolsPage;
375
+ }
341
376
  getConsoleData(includePreservedMessages) {
342
377
  return this.consoleCollector.getData(includePreservedMessages);
343
378
  }
@@ -374,6 +409,8 @@ export class McpPage {
374
409
  return helper.waitForEventsAfterAction(action, options);
375
410
  }
376
411
  dispose() {
412
+ this.#commentBridge?.dispose();
413
+ this.#commentBridge = undefined;
377
414
  this.pptrPage.off('dialog', this.#dialogHandler);
378
415
  this.networkCollector.dispose();
379
416
  this.consoleCollector.dispose();
@@ -544,7 +581,7 @@ export class McpPage {
544
581
  }
545
582
  async getElementByUid(uid) {
546
583
  if (!this.textSnapshot) {
547
- throw new Error(`No snapshot found for page ${this.id ?? '?'}. Use ${takeSnapshot.name} to capture one.`);
584
+ throw new Error(`No snapshot found for page ${this.id ?? '?'}. Use take_snapshot to capture one.`);
548
585
  }
549
586
  const node = this.textSnapshot.idToNode.get(uid);
550
587
  if (!node) {
@@ -570,6 +607,77 @@ export class McpPage {
570
607
  getAXNodeByUid(uid) {
571
608
  return this.textSnapshot?.idToNode.get(uid);
572
609
  }
610
+ async resolveBackendNodeId(backendNodeId) {
611
+ if (!this.textSnapshot) {
612
+ this.textSnapshot = await TextSnapshot.create(this);
613
+ }
614
+ let id = this.textSnapshot.resolveCdpElementId(backendNodeId);
615
+ if (!id) {
616
+ this.textSnapshot = await TextSnapshot.create(this);
617
+ id = this.textSnapshot.resolveCdpElementId(backendNodeId);
618
+ }
619
+ return id;
620
+ }
621
+ async resolveUidToBackendNodeId(uid) {
622
+ const target = this.pptrPage.target();
623
+ const targetId = Boolean(target) &&
624
+ '_targetId' in target &&
625
+ typeof target._targetId === 'string'
626
+ ? target._targetId
627
+ : undefined;
628
+ const node = this.getAXNodeByUid(uid);
629
+ if (node?.backendNodeId !== undefined) {
630
+ return { backendNodeId: node.backendNodeId, targetId };
631
+ }
632
+ try {
633
+ const handle = await this.getElementByUid(uid);
634
+ const backendNodeId = await handle.backendNodeId();
635
+ return backendNodeId ? { backendNodeId, targetId } : undefined;
636
+ }
637
+ catch {
638
+ return undefined;
639
+ }
640
+ }
641
+ async getMatchedStylesForUid(uid) {
642
+ if (!this.textSnapshot) {
643
+ throw new Error(`No snapshot found for page ${this.id ?? '?'}. Use take_snapshot to capture one.`);
644
+ }
645
+ const node = this.textSnapshot.idToNode.get(uid);
646
+ if (!node) {
647
+ throw new Error(`Element uid "${uid}" not found on page ${this.id}.`);
648
+ }
649
+ const backendNodeId = node.backendNodeId;
650
+ if (!isBackendNodeId(backendNodeId)) {
651
+ throw new Error(`Failed to resolve backend node ID for element with uid "${uid}".`);
652
+ }
653
+ if (!this.#devtoolsUniverse) {
654
+ throw new Error(`DevTools universe is not available for page ${this.id ?? '?'}.`);
655
+ }
656
+ const targetManager = this.#devtoolsUniverse.universe.context.get(DevTools.TargetManager);
657
+ let domNode;
658
+ let cssModel = null;
659
+ for (const dom of targetManager.models(DevTools.DOMModel.DOMModel)) {
660
+ const nodeMap = await dom.pushNodesByBackendIdsToFrontend(new Set([backendNodeId]));
661
+ const frontendNode = nodeMap?.get(backendNodeId);
662
+ if (frontendNode) {
663
+ domNode = frontendNode;
664
+ cssModel = dom.target().model(DevTools.CSSModel.CSSModel);
665
+ break;
666
+ }
667
+ }
668
+ if (!domNode || !cssModel) {
669
+ throw new Error(`Element with uid "${uid}" was detached or no longer exists on the page. Please take a new snapshot with take_snapshot.`);
670
+ }
671
+ const targetElement = domNode.enclosingElementOrSelf();
672
+ if (!targetElement) {
673
+ throw new Error(`Element with uid "${uid}" is not an element node and has no parent element.`);
674
+ }
675
+ const matchedStyles = await cssModel.getMatchedStyles(targetElement.id);
676
+ if (!matchedStyles) {
677
+ throw new Error(`Could not retrieve matched styles for element with uid "${uid}".`);
678
+ }
679
+ return matchedStyles;
680
+ }
573
681
  async getDevToolsData() {
574
682
  try {
575
683
  logger?.('Getting DevTools UI data');
@@ -3,7 +3,9 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { CommentFormatter, } from './formatters/CommentFormatter.js';
6
7
  import { ConsoleFormatter } from './formatters/ConsoleFormatter.js';
8
+ import { CssFormatter, resolveContainerQueries, } from './formatters/CssFormatter.js';
7
9
  import { HeapSnapshotFormatter, isEdgeLike, isNodeLike, } from './formatters/HeapSnapshotFormatter.js';
8
10
  import { IssueFormatter } from './formatters/IssueFormatter.js';
9
11
  import { NetworkFormatter } from './formatters/NetworkFormatter.js';
@@ -32,6 +34,7 @@ export class McpResponse {
32
34
  #heapSnapshotOptions;
33
35
  #networkRequestsOptions;
34
36
  #consoleDataOptions;
37
+ #cssStylesData;
35
38
  #listExtensions;
36
39
  #listThirdPartyDeveloperTools;
37
40
  #listWebMcpTools;
@@ -43,6 +46,7 @@ export class McpResponse {
43
46
  #error;
44
47
  #attachedWaitForResult;
45
48
  #reconnectNotice = false;
49
+ #devToolsComments;
46
50
  get #deviceScope() {
47
51
  return this.#page?.viewport?.isMobile ? 'PHONE' : 'DESKTOP';
48
52
  }
@@ -126,6 +130,12 @@ export class McpResponse {
126
130
  serviceWorkerId: options?.serviceWorkerId,
127
131
  };
128
132
  }
133
+ setIncludeCssStyles(matchedStyles, options) {
134
+ this.#cssStylesData = {
135
+ matchedStyles,
136
+ options,
137
+ };
138
+ }
129
139
  setError(error) {
130
140
  this.#error = error;
131
141
  }
@@ -188,6 +198,12 @@ export class McpResponse {
188
198
  attachWaitForResult(result) {
189
199
  this.#attachedWaitForResult = result;
190
200
  }
201
+ setDevToolsComments(threads) {
202
+ this.#devToolsComments = threads;
203
+ }
204
+ get devToolsComments() {
205
+ return this.#devToolsComments;
206
+ }
191
207
  setHeapSnapshotAggregates(aggregateData, options) {
192
208
  this.#heapSnapshotOptions = {
193
209
  ...this.#heapSnapshotOptions,
@@ -437,8 +453,23 @@ export class McpResponse {
437
453
  redactNetworkHeaders: this.#redactNetworkHeaders,
438
454
  })));
439
455
  }
456
+ async #handleComments() {
457
+ const comments = this.#devToolsComments;
458
+ if (!comments) {
459
+ return undefined;
460
+ }
461
+ const page = this.#page;
462
+ return await CommentFormatter.from(comments, {
463
+ resolveBackendNodeId: page
464
+ ? (id) => page.resolveBackendNodeId(id)
465
+ : undefined,
466
+ resolveCdpRequestId: page
467
+ ? (id) => page.resolveCdpRequestId(id)
468
+ : undefined,
469
+ });
470
+ }
440
471
  async handle(context, dataFormat = 'default') {
441
- const [snapshot, detailedNetworkRequest, detailedConsoleMessage, thirdPartyDeveloperTools, webmcpTools, consoleMessages, networkRequests,] = await Promise.all([
472
+ const [snapshot, detailedNetworkRequest, detailedConsoleMessage, thirdPartyDeveloperTools, webmcpTools, consoleMessages, networkRequests, comments,] = await Promise.all([
442
473
  this.#handleSnapshot(context),
443
474
  this.#handleAttachedNetworkRequest(context),
444
475
  this.#handleAttachedConsoleMessage(),
@@ -446,6 +477,7 @@ export class McpResponse {
446
477
  this.#handleWebMCP(),
447
478
  this.#handleConsoleList(context),
448
479
  this.#handleNetworkRequestList(context),
480
+ this.#handleComments(),
449
481
  ]);
450
482
  if (this.#includeExtensionServiceWorkers) {
451
483
  await context.createExtensionServiceWorkersSnapshot();
@@ -466,6 +498,7 @@ export class McpResponse {
466
498
  lighthouseResult: this.#attachedLighthouseResult,
467
499
  thirdPartyDeveloperTools,
468
500
  webmcpTools,
501
+ comments,
469
502
  errorMessage: this.#error?.message,
470
503
  }, dataFormat);
471
504
  }
@@ -504,7 +537,7 @@ export class McpResponse {
504
537
  const response = [];
505
538
  if (this.#reconnectNotice) {
506
539
  structuredContent.reconnected = true;
507
- response.push(`Note: the browser was restarted or reconnected since the last call. Page ids have changed. Call ${listPages().name} to see open pages.`);
540
+ response.push(`Note: the browser was restarted or reconnected since the last call. Page ids have changed. Call ${listPages(this.#args).name} to see open pages.`);
508
541
  }
509
542
  if (this.#textResponseLines.length) {
510
543
  structuredContent.message = this.#textResponseLines.join('\n');
@@ -557,7 +590,7 @@ export class McpResponse {
557
590
  : '';
558
591
  response.push(`# Open dialog
559
592
  ${dialog.type()}: ${dialog.message()}${defaultValueIfNeeded}.
560
- Call ${handleDialog.name} to handle it before continuing.`);
593
+ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
561
594
  structuredContent.dialog = {
562
595
  type: dialog.type(),
563
596
  message: dialog.message(),
@@ -939,6 +972,38 @@ Call ${handleDialog.name} to handle it before continuing.`);
939
972
  response.push('<no console messages found>');
940
973
  }
941
974
  }
975
+ if (data.comments) {
976
+ const commentsJson = data.comments.toJSON();
977
+ structuredContent.comments = commentsJson;
978
+ response.push(compactEncode ? compactEncode(commentsJson) : data.comments.toString());
979
+ }
980
+ if (this.#cssStylesData) {
981
+ const resolveUid = (backendNodeId) => this.#page?.textSnapshot?.resolveCdpElementId(backendNodeId);
982
+ const containerDetails = await resolveContainerQueries(this.#cssStylesData.matchedStyles, resolveUid);
983
+ const options = {
984
+ ...this.#cssStylesData.options,
985
+ resolveUid,
986
+ containerDetails,
987
+ };
988
+ const allRules = CssFormatter.collectRules(this.#cssStylesData.matchedStyles, options);
989
+ let rules = allRules;
990
+ const hasPagination = this.#cssStylesData.options.pageSize !== undefined ||
991
+ this.#cssStylesData.options.pageIdx !== undefined;
992
+ if (hasPagination) {
993
+ const paginationData = this.#dataWithPagination(allRules, this.#cssStylesData.options);
994
+ structuredContent.pagination = paginationData.pagination;
995
+ response.push(...paginationData.info);
996
+ rules = paginationData.items;
997
+ }
998
+ const formatter = new CssFormatter(this.#cssStylesData.matchedStyles, options, rules);
999
+ structuredContent.matchedStyles = formatter.toJSON();
1000
+ if (compactEncode) {
1001
+ response.push(compactEncode(structuredContent.matchedStyles));
1002
+ }
1003
+ else {
1004
+ response.push(formatter.toString());
1005
+ }
1006
+ }
942
1007
  if (data.errorMessage) {
943
1008
  response.push(`Error: ${data.errorMessage}`);
944
1009
  structuredContent.errorMessage = data.errorMessage;