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
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import { logger } from '../utils/logger.js';
7
+ const DEFAULT_DEBOUNCE_MS = 200;
8
+ /**
9
+ * Manages the bidirectional bridge between DevTools frontend comments
10
+ * and the MCP server notification system.
11
+ */
12
+ export class DevToolsCommentBridge {
13
+ #onNotification;
14
+ #debounceMs;
15
+ #commentDebounceTimer;
16
+ #attachedPages = new Set();
17
+ constructor(options) {
18
+ this.#onNotification = options?.onNotification;
19
+ this.#debounceMs = options?.debounceMs ?? DEFAULT_DEBOUNCE_MS;
20
+ }
21
+ isAttached(devtoolsPage) {
22
+ return this.#attachedPages.has(devtoolsPage);
23
+ }
24
+ async attach(devtoolsPage) {
25
+ if (this.#attachedPages.has(devtoolsPage)) {
26
+ return;
27
+ }
28
+ this.#attachedPages.add(devtoolsPage);
29
+ try {
30
+ await devtoolsPage.exposeFunction('__onDevToolsCommentEvent', () => {
31
+ this.#handleCommentEvent();
32
+ });
33
+ }
34
+ catch (e) {
35
+ logger?.('DevToolsCommentBridge: exposeFunction already bound or failed', e);
36
+ }
37
+ try {
38
+ await devtoolsPage.evaluate(() => {
39
+ window.__onDevToolsCommentListener = () => {
40
+ window.__onDevToolsCommentEvent?.();
41
+ };
42
+ window.universe?.cd4aBridge?.addEventListener('CommentThreadsChanged', window.__onDevToolsCommentListener);
43
+ window.universe?.cd4aBridge?.setAgentAttached(true);
44
+ });
45
+ }
46
+ catch (e) {
47
+ logger?.('DevToolsCommentBridge: evaluate failed', e);
48
+ }
49
+ }
50
+ async getComments(devtoolsPage) {
51
+ return await devtoolsPage.evaluate(() => {
52
+ window.universe?.cd4aBridge?.setAgentAttached(true);
53
+ return window.universe?.cd4aBridge?.getCommentThreads() ?? [];
54
+ });
55
+ }
56
+ #handleCommentEvent() {
57
+ if (this.#commentDebounceTimer) {
58
+ clearTimeout(this.#commentDebounceTimer);
59
+ }
60
+ this.#commentDebounceTimer = setTimeout(() => {
61
+ this.#onNotification?.('DevTools comment threads updated');
62
+ }, this.#debounceMs);
63
+ }
64
+ dispose() {
65
+ if (this.#commentDebounceTimer) {
66
+ clearTimeout(this.#commentDebounceTimer);
67
+ this.#commentDebounceTimer = undefined;
68
+ }
69
+ for (const page of this.#attachedPages) {
70
+ try {
71
+ const result = page.evaluate(() => {
72
+ if (window.__onDevToolsCommentListener) {
73
+ window.universe?.cd4aBridge?.removeEventListener?.('CommentThreadsChanged', window.__onDevToolsCommentListener);
74
+ delete window.__onDevToolsCommentListener;
75
+ }
76
+ window.universe?.cd4aBridge?.setAgentAttached(false);
77
+ });
78
+ if (result && typeof result.catch === 'function') {
79
+ void result.catch(e => {
80
+ logger?.('DevToolsCommentBridge: failed to remove event listener', e);
81
+ });
82
+ }
83
+ }
84
+ catch (e) {
85
+ logger?.('DevToolsCommentBridge: failed to remove event listener', e);
86
+ }
87
+ }
88
+ this.#attachedPages.clear();
89
+ }
90
+ }
91
+ //# sourceMappingURL=DevToolsCommentBridge.js.map
@@ -19,6 +19,11 @@ export function overrideDevToolsGlobals({ loadResource, }) {
19
19
  DevTools.Host.InspectorFrontendHost.installInspectorFrontendHost(new McpHostBindingAdapter(loadResource));
20
20
  // DevTools CDP errors can get noisy.
21
21
  DevTools.ProtocolClient.InspectorBackend.test.suppressRequestErrors = true;
22
+ const noopAgentCommand = () => {
23
+ return Promise.resolve({
24
+ getError: () => undefined,
25
+ });
26
+ };
22
27
  // Stub out Network emulation commands on the DevTools Agent prototype globally.
23
28
  // This prevents the DevTools Frontend from ever resetting/clearing Puppeteer's
24
29
  // active network blocking/throttling rules during target setup or session lifetime.
@@ -36,41 +41,37 @@ export function overrideDevToolsGlobals({ loadResource, }) {
36
41
  enumerable: true,
37
42
  });
38
43
  Object.defineProperty(networkAgentPrototype, 'invoke_overrideNetworkState', {
39
- value: () => {
40
- return Promise.resolve({
41
- getError: () => undefined,
42
- });
43
- },
44
+ value: noopAgentCommand,
44
45
  writable: true,
45
46
  configurable: true,
46
47
  enumerable: true,
47
48
  });
48
49
  Object.defineProperty(networkAgentPrototype, 'invoke_enable', {
49
- value: () => {
50
- return Promise.resolve({
51
- getError: () => undefined,
52
- });
53
- },
50
+ value: noopAgentCommand,
54
51
  writable: true,
55
52
  configurable: true,
56
53
  enumerable: true,
57
54
  });
58
55
  Object.defineProperty(networkAgentPrototype, 'invoke_disable', {
59
- value: () => {
60
- return Promise.resolve({
61
- getError: () => undefined,
62
- });
63
- },
56
+ value: noopAgentCommand,
64
57
  writable: true,
65
58
  configurable: true,
66
59
  enumerable: true,
67
60
  });
68
61
  Object.defineProperty(networkAgentPrototype, 'invoke_setBlockedURLs', {
69
- value: () => {
70
- return Promise.resolve({
71
- getError: () => undefined,
72
- });
73
- },
62
+ value: noopAgentCommand,
63
+ writable: true,
64
+ configurable: true,
65
+ enumerable: true,
66
+ });
67
+ }
68
+ // Puppeteer already collects issues from its own Audits subscription. Avoid
69
+ // enabling the DevTools Frontend's redundant subscription, which can replay
70
+ // a large retained issue backlog and delay unrelated page work.
71
+ const auditsAgentPrototype = DevTools.ProtocolClient.InspectorBackend.inspectorBackend.agentPrototypes.get('Audits');
72
+ if (auditsAgentPrototype) {
73
+ Object.defineProperty(auditsAgentPrototype, 'invoke_enable', {
74
+ value: noopAgentCommand,
74
75
  writable: true,
75
76
  configurable: true,
76
77
  enumerable: true,
@@ -91,7 +92,7 @@ export function overrideDevToolsGlobals({ loadResource, }) {
91
92
  .resolve('../third_party/devtools-formatter-worker.js'),
92
93
  });
93
94
  }
94
- export async function createTargetUniverse(session) {
95
+ export async function createTargetUniverse(session, options) {
95
96
  const settingStorage = new DevTools.Common.Settings.SettingsStorage({});
96
97
  const universe = new DevTools.Foundation.Universe.Universe({
97
98
  settingsCreationOptions: {
@@ -105,6 +106,11 @@ export async function createTargetUniverse(session) {
105
106
  inspectorFrontendHost: DevTools.Host.InspectorFrontendHost.InspectorFrontendHostInstance,
106
107
  supportsEmulation: false,
107
108
  });
109
+ const sourceMaps = options?.sourceMaps ?? true;
110
+ const jsSourceMapsSetting = universe.settings.resolve(DevTools.SDKSettings.jsSourceMapsEnabledSettingDescriptor);
111
+ jsSourceMapsSetting.set(sourceMaps);
112
+ const cssSourceMapsSetting = universe.settings.resolve(DevTools.SDKSettings.cssSourceMapsEnabledSettingDescriptor);
113
+ cssSourceMapsSetting.set(sourceMaps);
108
114
  const setting = universe.settings.resolve(DevTools.SourceMapManager.lazyLoadingSettingDescriptor);
109
115
  setting.set(true);
110
116
  const skipAllPausesSetting = universe.settings.resolve(DevTools.skipAllPausesSettingDescriptor);
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ function formatCommentThread(thread) {
7
+ const lines = [
8
+ `### Thread: ${thread.id}`,
9
+ `- Comment: ${thread.text}`,
10
+ ];
11
+ if (thread.elementUid) {
12
+ lines.push(`- Target element (snapshot UID): ${thread.elementUid}`);
13
+ }
14
+ if (thread.reqid !== undefined) {
15
+ lines.push(`- Network request ID (reqid): ${thread.reqid}`);
16
+ }
17
+ if (thread.editor) {
18
+ const location = thread.editor.filePath
19
+ ? `${thread.editor.filePath}:${thread.editor.lineNumber}`
20
+ : `line ${thread.editor.lineNumber}`;
21
+ lines.push(`- Editor location: ${location}`);
22
+ }
23
+ return lines.join('\n');
24
+ }
25
+ function formatComments(threads) {
26
+ if (threads.length === 0) {
27
+ return 'No open DevTools comments found.';
28
+ }
29
+ const lines = [
30
+ `Found ${threads.length} DevTools comment thread(s):`,
31
+ ];
32
+ for (const thread of threads) {
33
+ lines.push(`\n${formatCommentThread(thread)}`);
34
+ }
35
+ return lines.join('\n');
36
+ }
37
+ export class CommentFormatter {
38
+ #threads;
39
+ constructor(threads) {
40
+ this.#threads = threads;
41
+ }
42
+ static async from(threads, options) {
43
+ const structuredThreads = [];
44
+ for (const thread of threads) {
45
+ let elementUid;
46
+ const resolveBackendNodeId = options?.resolveBackendNodeId;
47
+ if (thread.backendNodeId !== undefined && resolveBackendNodeId) {
48
+ elementUid = await resolveBackendNodeId(thread.backendNodeId);
49
+ }
50
+ let reqid;
51
+ const resolveCdpRequestId = options?.resolveCdpRequestId;
52
+ if (thread.networkRequestId !== undefined && resolveCdpRequestId) {
53
+ reqid = resolveCdpRequestId(thread.networkRequestId);
54
+ }
55
+ const item = {
56
+ id: thread.id,
57
+ text: thread.text,
58
+ };
59
+ if (elementUid) {
60
+ item.elementUid = elementUid;
61
+ }
62
+ if (reqid !== undefined) {
63
+ item.reqid = reqid;
64
+ }
65
+ if (thread.editor) {
66
+ item.editor = thread.editor;
67
+ }
68
+ structuredThreads.push(item);
69
+ }
70
+ return new CommentFormatter(structuredThreads);
71
+ }
72
+ static formatThread(thread) {
73
+ return formatCommentThread(thread);
74
+ }
75
+ toJSON() {
76
+ return [...this.#threads];
77
+ }
78
+ toString() {
79
+ return formatComments(this.toJSON());
80
+ }
81
+ }
82
+ //# sourceMappingURL=CommentFormatter.js.map