chrome-devtools-mcp 1.7.0 → 1.8.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.
- package/README.md +48 -14
- package/build/src/McpContext.js +60 -24
- package/build/src/McpPage.js +5 -3
- package/build/src/McpResponse.js +22 -4
- package/build/src/ToolHandler.js +66 -12
- package/build/src/bin/chrome-devtools-mcp-main.js +2 -2
- package/build/src/bin/chrome-devtools.js +29 -30
- package/build/src/browser.js +3 -1
- package/build/src/{PageCollector.js → collectors/PageCollector.js} +7 -7
- package/build/src/{ServiceWorkerCollector.js → collectors/ServiceWorkerCollector.js} +1 -1
- package/build/src/{bin/chrome-devtools-cli-options.js → config/cli-options.js} +378 -23
- package/build/src/{bin/chrome-devtools-mcp-cli-options.js → config/mcp-options.js} +73 -8
- package/build/src/daemon/client.js +11 -2
- package/build/src/daemon/daemon.js +2 -2
- package/build/src/devtools/DevtoolsUtils.js +2 -14
- package/build/src/formatters/ConsoleFormatter.js +43 -10
- package/build/src/formatters/HeapSnapshotFormatter.js +10 -2
- package/build/src/formatters/IssueFormatter.js +1 -1
- package/build/src/formatters/NetworkFormatter.js +7 -7
- package/build/src/index.js +33 -5
- package/build/src/{HeapSnapshotManager.js → processors/HeapSnapshotManager.js} +21 -5
- package/build/src/{trace-processing/parse.js → processors/PerformanceTrace.js} +1 -1
- package/build/src/telemetry/ClearcutLogger.js +13 -1
- package/build/src/telemetry/flagUtils.js +4 -3
- package/build/src/telemetry/types.js +4 -0
- package/build/src/third_party/THIRD_PARTY_NOTICES +6 -63
- package/build/src/third_party/bundled-packages.json +4 -4
- package/build/src/third_party/devtools-heap-snapshot-worker.js +274 -42
- package/build/src/third_party/index.js +35378 -35538
- package/build/src/third_party/issue-descriptions/connectionAllowlistEmbeddingRequirementNotSatisfied.md +26 -0
- package/build/src/third_party/issue-descriptions/connectionAllowlistIFrameAttributeLoosensEmbeddingRequirement.md +19 -0
- package/build/src/third_party/issue-descriptions/connectionAllowlistInvalidAllowConnectionAllowlistFrom.md +21 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestAccountsBlockedByConnectionAllowlist.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestConfigBlockedByConnectionAllowlist.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestIdTokenBlockedByConnectionAllowlist.md +1 -0
- package/build/src/third_party/issue-descriptions/federatedAuthRequestWellKnownBlockedByConnectionAllowlist.md +1 -0
- package/build/src/tools/categories.js +3 -0
- package/build/src/tools/console.js +9 -3
- package/build/src/tools/emulation.js +2 -2
- package/build/src/tools/extensions.js +7 -5
- package/build/src/tools/input.js +26 -16
- package/build/src/tools/lighthouse.js +3 -1
- package/build/src/tools/memory.js +112 -16
- package/build/src/tools/network.js +6 -3
- package/build/src/tools/pages.js +12 -16
- package/build/src/tools/performance.js +15 -25
- package/build/src/tools/pwa.js +128 -0
- package/build/src/tools/screencast.js +6 -4
- package/build/src/tools/screenshot.js +42 -9
- package/build/src/tools/script.js +28 -8
- package/build/src/tools/slim/tools.js +3 -3
- package/build/src/tools/snapshot.js +5 -3
- package/build/src/tools/thirdPartyDeveloper.js +2 -2
- package/build/src/tools/tools.js +2 -0
- package/build/src/tools/webmcp.js +2 -2
- package/build/src/{WaitForHelper.js → utils/WaitForHelper.js} +63 -38
- package/build/src/utils/bytes.js +105 -0
- package/build/src/utils/logger.js +25 -11
- package/build/src/version.js +1 -1
- package/package.json +20 -12
- package/skills/a11y-debugging/SKILL.md +2 -0
- package/skills/chrome-devtools/SKILL.md +5 -4
- package/skills/chrome-devtools-cli/SKILL.md +109 -64
- package/skills/debug-optimize-lcp/SKILL.md +9 -9
- package/skills/memory-leak-debugging/SKILL.md +2 -2
- package/skills/troubleshooting/SKILL.md +1 -0
- package/build/src/utils/string.js +0 -37
package/README.md
CHANGED
|
@@ -136,6 +136,26 @@ Chrome DevTools MCP will not start the browser instance automatically using this
|
|
|
136
136
|
|
|
137
137
|
</details>
|
|
138
138
|
|
|
139
|
+
<details>
|
|
140
|
+
<summary>Bob</summary>
|
|
141
|
+
|
|
142
|
+
Follow the <a href="https://bob.ibm.com/docs/ide/configuration/mcp/mcp-in-bob">IBM Bob MCP guide</a> and add the Chrome DevTools MCP server to your Bob MCP configuration. Use the global config (`~/.bob/mcp.json`) to apply it across all workspaces, or a project config (`.bob/mcp.json`) to scope it to one project:
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"mcpServers": {
|
|
147
|
+
"chrome-devtools": {
|
|
148
|
+
"command": "npx",
|
|
149
|
+
"args": ["-y", "chrome-devtools-mcp@latest"]
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
You can edit these files from **Bob panel → Settings → MCP → Edit Global MCP** (or **Edit Project MCP**). Bob hot-reloads on save. Once the server appears in the MCP tab, switch to the **🌎 Browser Dev** mode to get guided browser debugging directly in Bob.
|
|
156
|
+
|
|
157
|
+
</details>
|
|
158
|
+
|
|
139
159
|
<details>
|
|
140
160
|
<summary>Claude Code</summary>
|
|
141
161
|
|
|
@@ -537,7 +557,7 @@ If you run into any issues, checkout our [troubleshooting guide](./docs/troubles
|
|
|
537
557
|
- [`take_snapshot`](docs/tool-reference.md#take_snapshot)
|
|
538
558
|
- [`screencast_start`](docs/tool-reference.md#screencast_start)
|
|
539
559
|
- [`screencast_stop`](docs/tool-reference.md#screencast_stop)
|
|
540
|
-
- **Memory** (
|
|
560
|
+
- **Memory** (13 tools)
|
|
541
561
|
- [`take_heapsnapshot`](docs/tool-reference.md#take_heapsnapshot)
|
|
542
562
|
- [`close_heapsnapshot`](docs/tool-reference.md#close_heapsnapshot)
|
|
543
563
|
- [`compare_heapsnapshots`](docs/tool-reference.md#compare_heapsnapshots)
|
|
@@ -550,6 +570,7 @@ If you run into any issues, checkout our [troubleshooting guide](./docs/troubles
|
|
|
550
570
|
- [`get_heapsnapshot_retainers`](docs/tool-reference.md#get_heapsnapshot_retainers)
|
|
551
571
|
- [`get_heapsnapshot_retaining_paths`](docs/tool-reference.md#get_heapsnapshot_retaining_paths)
|
|
552
572
|
- [`get_heapsnapshot_summary`](docs/tool-reference.md#get_heapsnapshot_summary)
|
|
573
|
+
- [`query_heapsnapshot_objects`](docs/tool-reference.md#query_heapsnapshot_objects)
|
|
553
574
|
- **Extensions** (5 tools)
|
|
554
575
|
- [`install_extension`](docs/tool-reference.md#install_extension)
|
|
555
576
|
- [`list_extensions`](docs/tool-reference.md#list_extensions)
|
|
@@ -562,6 +583,11 @@ If you run into any issues, checkout our [troubleshooting guide](./docs/troubles
|
|
|
562
583
|
- **WebMCP** (2 tools)
|
|
563
584
|
- [`execute_webmcp_tool`](docs/tool-reference.md#execute_webmcp_tool)
|
|
564
585
|
- [`list_webmcp_tools`](docs/tool-reference.md#list_webmcp_tools)
|
|
586
|
+
- **Progressive Web Apps** (4 tools)
|
|
587
|
+
- [`get_os_app_state`](docs/tool-reference.md#get_os_app_state)
|
|
588
|
+
- [`install_pwa`](docs/tool-reference.md#install_pwa)
|
|
589
|
+
- [`launch_pwa`](docs/tool-reference.md#launch_pwa)
|
|
590
|
+
- [`uninstall_pwa`](docs/tool-reference.md#uninstall_pwa)
|
|
565
591
|
|
|
566
592
|
<!-- END AUTO GENERATED TOOLS -->
|
|
567
593
|
|
|
@@ -637,10 +663,10 @@ The Chrome DevTools MCP server supports the following configuration option:
|
|
|
637
663
|
- **Type:** boolean
|
|
638
664
|
- **Default:** `false`
|
|
639
665
|
|
|
640
|
-
- **`--
|
|
641
|
-
|
|
666
|
+
- **`--pageIdRouting`/ `--page-id-routing`**
|
|
667
|
+
Require pageId on page-scoped tools and route requests by page ID (useful for concurrent agent sessions). Use --no-page-id-routing to disable.
|
|
642
668
|
- **Type:** boolean
|
|
643
|
-
- **Default:** `
|
|
669
|
+
- **Default:** `true`
|
|
644
670
|
|
|
645
671
|
- **`--experimentalDevtools`/ `--experimental-devtools`**
|
|
646
672
|
Whether to enable automation over DevTools targets
|
|
@@ -727,6 +753,11 @@ The Chrome DevTools MCP server supports the following configuration option:
|
|
|
727
753
|
- **Type:** boolean
|
|
728
754
|
- **Default:** `false`
|
|
729
755
|
|
|
756
|
+
- **`--categoryPwa`/ `--category-pwa`**
|
|
757
|
+
Set to true to include tools for automating Progressive Web Apps (install, launch, uninstall, and OS state). This feature is only supported with a pipe connection; autoConnect, browserUrl, and wsEndpoint are not supported.
|
|
758
|
+
- **Type:** boolean
|
|
759
|
+
- **Default:** `false`
|
|
760
|
+
|
|
730
761
|
- **`--performanceCrux`/ `--performance-crux`**
|
|
731
762
|
Set to false to disable sending URLs from performance traces to CrUX API to get field performance data.
|
|
732
763
|
- **Type:** boolean
|
|
@@ -820,22 +851,25 @@ You can also run `npx chrome-devtools-mcp@latest --help` to see all available co
|
|
|
820
851
|
|
|
821
852
|
### Concurrent sessions
|
|
822
853
|
|
|
823
|
-
Most MCP clients start one Chrome DevTools MCP server per conversation.
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
with.
|
|
854
|
+
Most MCP clients start one Chrome DevTools MCP server per conversation.
|
|
855
|
+
By default, the server runs with `--pageIdRouting` enabled, making `pageId` a
|
|
856
|
+
required parameter on page-scoped tools (such as `click`, `fill`, `navigate_page`,
|
|
857
|
+
`take_snapshot`, etc.) so multiple agents or subagents sharing a server instance can
|
|
858
|
+
route tool calls directly to the specific tab they are working with.
|
|
859
|
+
|
|
860
|
+
For `evaluate_script`, `pageId` is required by default for targeting pages, but
|
|
861
|
+
becomes optional when `--categoryExtensions` is enabled so that `serviceWorkerId`
|
|
862
|
+
can be specified instead to evaluate inside an extension background service worker.
|
|
863
|
+
|
|
864
|
+
To disable this behavior and default to the currently selected page, pass
|
|
865
|
+
`--no-page-id-routing`.
|
|
828
866
|
|
|
829
867
|
```json
|
|
830
868
|
{
|
|
831
869
|
"mcpServers": {
|
|
832
870
|
"chrome-devtools": {
|
|
833
871
|
"command": "npx",
|
|
834
|
-
"args": [
|
|
835
|
-
"-y",
|
|
836
|
-
"chrome-devtools-mcp@latest",
|
|
837
|
-
"--experimentalPageIdRouting"
|
|
838
|
-
]
|
|
872
|
+
"args": ["-y", "chrome-devtools-mcp@latest"]
|
|
839
873
|
}
|
|
840
874
|
}
|
|
841
875
|
}
|
package/build/src/McpContext.js
CHANGED
|
@@ -8,9 +8,9 @@ import os from 'node:os';
|
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
10
10
|
import { overrideDevToolsGlobals } from './devtools/DevtoolsUtils.js';
|
|
11
|
-
import { HeapSnapshotManager } from './HeapSnapshotManager.js';
|
|
11
|
+
import { HeapSnapshotManager } from './processors/HeapSnapshotManager.js';
|
|
12
12
|
import { McpPage } from './McpPage.js';
|
|
13
|
-
import { ServiceWorkerConsoleCollector } from './ServiceWorkerCollector.js';
|
|
13
|
+
import { ServiceWorkerConsoleCollector } from './collectors/ServiceWorkerCollector.js';
|
|
14
14
|
import { Locator, } from './third_party/index.js';
|
|
15
15
|
import { listPages } from './tools/pages.js';
|
|
16
16
|
import { CLOSE_PAGE_ERROR } from './tools/ToolDefinition.js';
|
|
@@ -137,28 +137,30 @@ export class McpContext {
|
|
|
137
137
|
}
|
|
138
138
|
async validatePath(filePath) {
|
|
139
139
|
if (filePath === undefined) {
|
|
140
|
-
return;
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
let canonicalPath;
|
|
143
|
+
try {
|
|
144
|
+
canonicalPath = await resolveCanonicalPath(filePath);
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
148
|
+
console.error(`[MCP Context] Error resolving real path for ${filePath}: ${errMsg}`);
|
|
149
|
+
throw new Error(`Access denied: Cannot resolve base path for ${filePath}.`);
|
|
141
150
|
}
|
|
142
151
|
// If the client never negotiated roots and the operator has explicitly
|
|
143
152
|
// opted into unrestricted access via --allow-unrestricted-paths, restore
|
|
144
153
|
// the previous permissive behavior and skip validation.
|
|
145
154
|
if (this.#roots === undefined && this.#allowUnrestrictedPaths) {
|
|
146
|
-
|
|
155
|
+
// Canonical path might not exist yet so we fallback to
|
|
156
|
+
// path.resolve(filePath). Consumers should not follow symlinks.
|
|
157
|
+
return canonicalPath || path.resolve(filePath);
|
|
147
158
|
}
|
|
148
159
|
// roots() always returns at least the temp directory, even if the
|
|
149
160
|
// connecting client never negotiated the optional `roots` capability.
|
|
150
161
|
// Path validation must not be skipped just because no workspace roots
|
|
151
162
|
// were configured.
|
|
152
163
|
const roots = this.roots();
|
|
153
|
-
let canonicalPath;
|
|
154
|
-
try {
|
|
155
|
-
canonicalPath = await resolveCanonicalPath(filePath);
|
|
156
|
-
}
|
|
157
|
-
catch (err) {
|
|
158
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
159
|
-
console.error(`[MCP Context] Error resolving real path for ${filePath}: ${errMsg}`);
|
|
160
|
-
throw new Error(`Access denied: Cannot resolve base path for ${filePath}.`);
|
|
161
|
-
}
|
|
162
164
|
let allowed = false;
|
|
163
165
|
const resolvedRoots = await Promise.allSettled(roots.map(async (root) => {
|
|
164
166
|
const rootPathUri = root.uri;
|
|
@@ -186,12 +188,12 @@ export class McpContext {
|
|
|
186
188
|
if (!allowed) {
|
|
187
189
|
throw new Error(`Access denied: path ${filePath} (canonical: ${canonicalPath}) is not within any of the configured workspace roots.`);
|
|
188
190
|
}
|
|
191
|
+
return canonicalPath || path.resolve(filePath);
|
|
189
192
|
}
|
|
190
193
|
async ensureExtension(filePath, extension) {
|
|
191
|
-
const
|
|
192
|
-
const currentExtension = path.extname(
|
|
193
|
-
const outputPath = `${
|
|
194
|
-
await this.validatePath(outputPath);
|
|
194
|
+
const resolved = await this.validatePath(filePath);
|
|
195
|
+
const currentExtension = path.extname(resolved);
|
|
196
|
+
const outputPath = `${resolved.slice(0, resolved.length - currentExtension.length)}${extension}`;
|
|
195
197
|
return outputPath;
|
|
196
198
|
}
|
|
197
199
|
async newPage(background, isolatedContextName) {
|
|
@@ -226,6 +228,18 @@ export class McpContext {
|
|
|
226
228
|
get #hasNetworkBlockOrAllowlist() {
|
|
227
229
|
return !!(this.#options.allowList || this.#options.blocklist);
|
|
228
230
|
}
|
|
231
|
+
installPWA(options) {
|
|
232
|
+
return this.browser.installPWA(options);
|
|
233
|
+
}
|
|
234
|
+
uninstallPWA(options) {
|
|
235
|
+
return this.browser.uninstallPWA(options);
|
|
236
|
+
}
|
|
237
|
+
launchPWA(options) {
|
|
238
|
+
return this.browser.launchPWA(options);
|
|
239
|
+
}
|
|
240
|
+
getPWAState(options) {
|
|
241
|
+
return this.browser.getPWAState(options);
|
|
242
|
+
}
|
|
229
243
|
setIsRunningPerformanceTrace(x) {
|
|
230
244
|
this.#isRunningTrace = x;
|
|
231
245
|
}
|
|
@@ -254,6 +268,21 @@ export class McpContext {
|
|
|
254
268
|
}
|
|
255
269
|
return page;
|
|
256
270
|
}
|
|
271
|
+
getSelectedMcpPageUrl(page) {
|
|
272
|
+
let targetPage = page;
|
|
273
|
+
if (!targetPage) {
|
|
274
|
+
try {
|
|
275
|
+
targetPage = this.getSelectedMcpPage();
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
return undefined;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (targetPage?.pptrPage?.isClosed() === false) {
|
|
282
|
+
return targetPage.pptrPage.url();
|
|
283
|
+
}
|
|
284
|
+
return undefined;
|
|
285
|
+
}
|
|
257
286
|
async getDevToolsData(page) {
|
|
258
287
|
const targetPage = page ?? this.#selectedPage;
|
|
259
288
|
if (!targetPage) {
|
|
@@ -359,6 +388,7 @@ export class McpContext {
|
|
|
359
388
|
locatorClass: this.#locatorClass,
|
|
360
389
|
hasNetworkBlockOrAllowlist: this.#hasNetworkBlockOrAllowlist,
|
|
361
390
|
isolatedContextName: this.#getBrowserContextToNameMap().get(page.browserContext()),
|
|
391
|
+
navigationTimeout: this.#options.navigationTimeout,
|
|
362
392
|
});
|
|
363
393
|
this.#mcpPages.set(page, mcpPage);
|
|
364
394
|
await mcpPage.init();
|
|
@@ -428,16 +458,16 @@ export class McpContext {
|
|
|
428
458
|
return this.#extensionServiceWorkerMap.get(extensionServiceWorker.target);
|
|
429
459
|
}
|
|
430
460
|
async #writeFile(filepath, data) {
|
|
431
|
-
await this.validatePath(filepath);
|
|
461
|
+
const resolved = await this.validatePath(filepath);
|
|
432
462
|
try {
|
|
433
|
-
await fs.mkdir(path.dirname(
|
|
463
|
+
await fs.mkdir(path.dirname(resolved), { recursive: true });
|
|
434
464
|
// Open the file with flags to:
|
|
435
465
|
// - O_WRONLY: Write-only
|
|
436
466
|
// - O_CREAT: Create if it doesn't exist
|
|
437
467
|
// - O_TRUNC: Truncate to zero length if it exists
|
|
438
468
|
// - O_NOFOLLOW: DO NOT follow symlinks.
|
|
439
469
|
// - 0o600: Permissions: read/write for owner, no permissions for others.
|
|
440
|
-
await fs.writeFile(
|
|
470
|
+
await fs.writeFile(resolved, data, {
|
|
441
471
|
flag: fs.constants.O_WRONLY |
|
|
442
472
|
fs.constants.O_CREAT |
|
|
443
473
|
fs.constants.O_TRUNC |
|
|
@@ -502,6 +532,9 @@ export class McpContext {
|
|
|
502
532
|
async getHeapSnapshotDuplicateStrings(filePath) {
|
|
503
533
|
return await this.#heapSnapshotManager.getDuplicateStrings(filePath);
|
|
504
534
|
}
|
|
535
|
+
async queryHeapSnapshotObjects(filePath, options) {
|
|
536
|
+
return await this.#heapSnapshotManager.queryObjects(filePath, options);
|
|
537
|
+
}
|
|
505
538
|
async getHeapSnapshotStats(filePath) {
|
|
506
539
|
return await this.#heapSnapshotManager.getStats(filePath);
|
|
507
540
|
}
|
|
@@ -511,6 +544,9 @@ export class McpContext {
|
|
|
511
544
|
async getHeapSnapshotNativeContextSizes(filePath) {
|
|
512
545
|
return await this.#heapSnapshotManager.getNativeContextSizes(filePath);
|
|
513
546
|
}
|
|
547
|
+
async getHeapSnapshotRetainedByContextSummary(filePath) {
|
|
548
|
+
return await this.#heapSnapshotManager.getRetainedByContextSummary(filePath);
|
|
549
|
+
}
|
|
514
550
|
async getHeapSnapshotNodesById(filePath, id, filterName, objectId) {
|
|
515
551
|
return await this.#heapSnapshotManager.getNodesById(filePath, id, filterName, objectId);
|
|
516
552
|
}
|
|
@@ -569,15 +605,15 @@ export class McpContext {
|
|
|
569
605
|
return response.text();
|
|
570
606
|
}
|
|
571
607
|
case 'file:': {
|
|
572
|
-
await this.validatePath(fileURLToPath(url));
|
|
573
|
-
return await fs.readFile(
|
|
608
|
+
const resolved = await this.validatePath(fileURLToPath(url));
|
|
609
|
+
return await fs.readFile(resolved, 'utf-8');
|
|
574
610
|
}
|
|
575
611
|
default:
|
|
576
612
|
throw new Error(`Unsupported protocol for: ${url}`);
|
|
577
613
|
}
|
|
578
614
|
}
|
|
579
|
-
async getHeapSnapshotEdges(filePath, nodeId) {
|
|
580
|
-
return await this.#heapSnapshotManager.getEdges(filePath, nodeId);
|
|
615
|
+
async getHeapSnapshotEdges(filePath, nodeId, options) {
|
|
616
|
+
return await this.#heapSnapshotManager.getEdges(filePath, nodeId, options);
|
|
581
617
|
}
|
|
582
618
|
async getHeapSnapshotClassDiffs(baseFilePath, currentFilePath) {
|
|
583
619
|
return await this.#heapSnapshotManager.getClassDiffs(baseFilePath, currentFilePath);
|
package/build/src/McpPage.js
CHANGED
|
@@ -102,14 +102,14 @@ export function replaceHtmlElementsWithUids(schema) {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
import { createTargetUniverse, } from './devtools/DevtoolsUtils.js';
|
|
105
|
-
import { ConsoleCollector, NetworkCollector, } from './PageCollector.js';
|
|
105
|
+
import { ConsoleCollector, NetworkCollector, } from './collectors/PageCollector.js';
|
|
106
106
|
import { TextSnapshot } from './TextSnapshot.js';
|
|
107
107
|
import { PredefinedNetworkConditions, } from './third_party/index.js';
|
|
108
108
|
import { takeSnapshot } from './tools/snapshot.js';
|
|
109
109
|
const DEFAULT_TIMEOUT = 5_000;
|
|
110
110
|
const NAVIGATION_TIMEOUT = 10_000;
|
|
111
111
|
import { logger } from './utils/logger.js';
|
|
112
|
-
import { getNetworkMultiplierFromString, WaitForHelper, } from './WaitForHelper.js';
|
|
112
|
+
import { getNetworkMultiplierFromString, WaitForHelper, } from './utils/WaitForHelper.js';
|
|
113
113
|
/**
|
|
114
114
|
* Per-page state wrapper. Consolidates dialog, snapshot, emulation,
|
|
115
115
|
* and metadata that were previously scattered across Maps in McpContext.
|
|
@@ -138,9 +138,11 @@ export class McpPage {
|
|
|
138
138
|
consoleCollector;
|
|
139
139
|
#hasNetworkBlockOrAllowlist;
|
|
140
140
|
#locatorClass;
|
|
141
|
+
#navigationTimeout;
|
|
141
142
|
constructor(page, id, options) {
|
|
142
143
|
this.#hasNetworkBlockOrAllowlist = options.hasNetworkBlockOrAllowlist;
|
|
143
144
|
this.#locatorClass = options.locatorClass;
|
|
145
|
+
this.#navigationTimeout = options.navigationTimeout ?? NAVIGATION_TIMEOUT;
|
|
144
146
|
this.pptrPage = page;
|
|
145
147
|
this.id = id;
|
|
146
148
|
this.isolatedContextName = options.isolatedContextName;
|
|
@@ -707,7 +709,7 @@ export class McpPage {
|
|
|
707
709
|
// navigations.
|
|
708
710
|
// Increased in case we throttle the network requests or the CPU
|
|
709
711
|
const networkMultiplier = getNetworkMultiplierFromString(this.networkConditions);
|
|
710
|
-
this.pptrPage.setDefaultNavigationTimeout(
|
|
712
|
+
this.pptrPage.setDefaultNavigationTimeout(this.#navigationTimeout * networkMultiplier * cpuMultiplier);
|
|
711
713
|
}
|
|
712
714
|
waitForTextOnPage(text, timeout) {
|
|
713
715
|
const frames = this.pptrPage.frames();
|
package/build/src/McpResponse.js
CHANGED
|
@@ -8,11 +8,11 @@ import { HeapSnapshotFormatter, isEdgeLike, isNodeLike, } from './formatters/Hea
|
|
|
8
8
|
import { IssueFormatter } from './formatters/IssueFormatter.js';
|
|
9
9
|
import { NetworkFormatter } from './formatters/NetworkFormatter.js';
|
|
10
10
|
import { SnapshotFormatter } from './formatters/SnapshotFormatter.js';
|
|
11
|
-
import { UncaughtError } from './PageCollector.js';
|
|
11
|
+
import { UncaughtError } from './collectors/PageCollector.js';
|
|
12
12
|
import { TextSnapshot } from './TextSnapshot.js';
|
|
13
13
|
import { DevTools, getToonEncode, getGcfEncode } from './third_party/index.js';
|
|
14
14
|
import { handleDialog, listPages } from './tools/pages.js';
|
|
15
|
-
import { getInsightOutput, getTraceSummary } from './
|
|
15
|
+
import { getInsightOutput, getTraceSummary, } from './processors/PerformanceTrace.js';
|
|
16
16
|
import { stableIdSymbol } from './utils/id.js';
|
|
17
17
|
import { paginate } from './utils/pagination.js';
|
|
18
18
|
const { formatBytesToKb } = DevTools.I18n.ByteUtilities;
|
|
@@ -122,6 +122,7 @@ export class McpResponse {
|
|
|
122
122
|
: undefined,
|
|
123
123
|
types: options?.types,
|
|
124
124
|
includePreservedMessages: options?.includePreservedMessages,
|
|
125
|
+
includeStackTraces: options?.includeStackTraces,
|
|
125
126
|
serviceWorkerId: options?.serviceWorkerId,
|
|
126
127
|
};
|
|
127
128
|
}
|
|
@@ -195,13 +196,14 @@ export class McpResponse {
|
|
|
195
196
|
pagination: options,
|
|
196
197
|
};
|
|
197
198
|
}
|
|
198
|
-
setHeapSnapshotStats(stats, staticData, nativeContextSizes) {
|
|
199
|
+
setHeapSnapshotStats(stats, staticData, nativeContextSizes, retainedByContextSummary) {
|
|
199
200
|
this.#heapSnapshotOptions = {
|
|
200
201
|
...this.#heapSnapshotOptions,
|
|
201
202
|
include: true,
|
|
202
203
|
stats,
|
|
203
204
|
staticData,
|
|
204
205
|
nativeContextSizes,
|
|
206
|
+
retainedByContextSummary,
|
|
205
207
|
};
|
|
206
208
|
}
|
|
207
209
|
setHeapSnapshotNodes(nodes, options) {
|
|
@@ -394,6 +396,7 @@ export class McpResponse {
|
|
|
394
396
|
return await ConsoleFormatter.from(consoleMessage, {
|
|
395
397
|
id: consoleMessageStableId,
|
|
396
398
|
fetchDetailedData: false,
|
|
399
|
+
fetchStackTrace: this.#consoleDataOptions?.includeStackTraces,
|
|
397
400
|
devTools: page ? page.devtoolsUniverse : undefined,
|
|
398
401
|
});
|
|
399
402
|
}
|
|
@@ -649,7 +652,11 @@ Call ${handleDialog.name} to handle it before continuing.`);
|
|
|
649
652
|
for (const [insightName, model] of Object.entries(insightSet.model)) {
|
|
650
653
|
structuredContent.traceInsights.push({
|
|
651
654
|
insightName,
|
|
652
|
-
insightKey: model
|
|
655
|
+
insightKey: typeof model === 'object' &&
|
|
656
|
+
model !== null &&
|
|
657
|
+
'insightKey' in model
|
|
658
|
+
? model.insightKey
|
|
659
|
+
: undefined,
|
|
653
660
|
});
|
|
654
661
|
}
|
|
655
662
|
}
|
|
@@ -717,6 +724,14 @@ Call ${handleDialog.name} to handle it before continuing.`);
|
|
|
717
724
|
structuredContent.heapSnapshot = structuredContent.heapSnapshot || {};
|
|
718
725
|
structuredContent.heapSnapshot.nativeContextSizes = nativeContextSizes;
|
|
719
726
|
}
|
|
727
|
+
const retainedByContextSummary = this.#heapSnapshotOptions.retainedByContextSummary;
|
|
728
|
+
if (retainedByContextSummary) {
|
|
729
|
+
response.push('### Retained by Context Summary');
|
|
730
|
+
response.push(HeapSnapshotFormatter.formatRetainedByContextSummary(retainedByContextSummary));
|
|
731
|
+
structuredContent.heapSnapshot = structuredContent.heapSnapshot || {};
|
|
732
|
+
structuredContent.heapSnapshot.retainedByContextSummary =
|
|
733
|
+
retainedByContextSummary;
|
|
734
|
+
}
|
|
720
735
|
const aggregateData = this.#heapSnapshotOptions.aggregateData;
|
|
721
736
|
if (aggregateData) {
|
|
722
737
|
const sortedEntries = HeapSnapshotFormatter.sort(aggregateData.aggregates);
|
|
@@ -916,6 +931,9 @@ Call ${handleDialog.name} to handle it before continuing.`);
|
|
|
916
931
|
else {
|
|
917
932
|
response.push(...paginationData.items.map(item => item.toString()));
|
|
918
933
|
}
|
|
934
|
+
if (structuredContent.consoleMessages.some(message => 'stackTrace' in message)) {
|
|
935
|
+
response.push('Note: stack trace line and column numbers use 1-based indexing');
|
|
936
|
+
}
|
|
919
937
|
}
|
|
920
938
|
else {
|
|
921
939
|
response.push('<no console messages found>');
|
package/build/src/ToolHandler.js
CHANGED
|
@@ -11,6 +11,8 @@ import { zod } from './third_party/index.js';
|
|
|
11
11
|
import { labels, OFF_BY_DEFAULT_CATEGORIES } from './tools/categories.js';
|
|
12
12
|
import { pageIdSchema } from './tools/ToolDefinition.js';
|
|
13
13
|
import { logger } from './utils/logger.js';
|
|
14
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
15
|
+
import { isLocalhost } from './utils/url.js';
|
|
14
16
|
export function buildFlag(category) {
|
|
15
17
|
return `category${category.charAt(0).toUpperCase() + category.slice(1)}`;
|
|
16
18
|
}
|
|
@@ -82,6 +84,66 @@ function buildUnknownArgumentsMessage(toolName, unknownArgumentNames, expectedAr
|
|
|
82
84
|
const correction = unknownArgumentNames.length === 1 ? 'Remove it' : 'Remove them';
|
|
83
85
|
return `Unknown ${unknownLabel} for tool "${toolName}": ${formatArgumentNames(unknownArgumentNames)}. ${expectedArguments} ${correction} and retry.`;
|
|
84
86
|
}
|
|
87
|
+
async function validateAndResolvePathOrUrl(filePathOrUrl, context) {
|
|
88
|
+
try {
|
|
89
|
+
const url = new URL(filePathOrUrl);
|
|
90
|
+
if (url.protocol === 'file:') {
|
|
91
|
+
return pathToFileURL(await context.validatePath(fileURLToPath(url))).href;
|
|
92
|
+
}
|
|
93
|
+
else if (['http:', 'https:', 'ws:', 'wss:'].includes(url.protocol)) {
|
|
94
|
+
return filePathOrUrl;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Suppress parsing errors for regular file paths.
|
|
99
|
+
}
|
|
100
|
+
return await context.validatePath(filePathOrUrl);
|
|
101
|
+
}
|
|
102
|
+
function isLocalBrowser(context) {
|
|
103
|
+
if (context.browser.process()) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
const wsEndpoint = context.browser.wsEndpoint();
|
|
107
|
+
if (wsEndpoint && isLocalhost(wsEndpoint)) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
function shouldValidateFile(option, isLocal) {
|
|
113
|
+
if (option === true) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
if (typeof option === 'object' && option !== null) {
|
|
117
|
+
if (isLocal) {
|
|
118
|
+
return Boolean(option.local);
|
|
119
|
+
}
|
|
120
|
+
return Boolean(option.remote);
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
async function validateToolFiles(tool, params, context) {
|
|
125
|
+
const isLocal = isLocalBrowser(context);
|
|
126
|
+
for (const [key, option] of Object.entries(tool.verifyFilesSchema)) {
|
|
127
|
+
if (shouldValidateFile(option, isLocal)) {
|
|
128
|
+
const val = params[key];
|
|
129
|
+
if (typeof val === 'string') {
|
|
130
|
+
params[key] = await validateAndResolvePathOrUrl(val, context);
|
|
131
|
+
}
|
|
132
|
+
else if (Array.isArray(val)) {
|
|
133
|
+
const updated = [];
|
|
134
|
+
for (const item of val) {
|
|
135
|
+
if (typeof item === 'string') {
|
|
136
|
+
updated.push(await validateAndResolvePathOrUrl(item, context));
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
throw new Error('Unexpected non-string value as a file path or URL');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
params[key] = updated;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
85
147
|
export class ToolHandler {
|
|
86
148
|
tool;
|
|
87
149
|
serverArgs;
|
|
@@ -102,7 +164,7 @@ export class ToolHandler {
|
|
|
102
164
|
this.inputSchema =
|
|
103
165
|
'pageScoped' in tool &&
|
|
104
166
|
tool.pageScoped &&
|
|
105
|
-
serverArgs.
|
|
167
|
+
serverArgs.pageIdRouting &&
|
|
106
168
|
!serverArgs.slim
|
|
107
169
|
? { ...pageIdSchema, ...tool.schema }
|
|
108
170
|
: tool.schema;
|
|
@@ -153,16 +215,11 @@ export class ToolHandler {
|
|
|
153
215
|
}
|
|
154
216
|
let page;
|
|
155
217
|
try {
|
|
156
|
-
|
|
157
|
-
for (const key of this.tool.verifyFilesSchema) {
|
|
158
|
-
const filePath = params[key];
|
|
159
|
-
await context.validatePath(filePath);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
218
|
+
await validateToolFiles(this.tool, params, context);
|
|
162
219
|
if (isPageScopedTool(this.tool)) {
|
|
163
220
|
const pageId = typeof params.pageId === 'number' ? params.pageId : undefined;
|
|
164
221
|
page =
|
|
165
|
-
this.serverArgs.
|
|
222
|
+
this.serverArgs.pageIdRouting &&
|
|
166
223
|
pageId !== undefined &&
|
|
167
224
|
!this.serverArgs.slim
|
|
168
225
|
? context.getPageById(pageId)
|
|
@@ -186,10 +243,7 @@ export class ToolHandler {
|
|
|
186
243
|
response.setError(err);
|
|
187
244
|
}
|
|
188
245
|
devToolsData = await context.getDevToolsData(page);
|
|
189
|
-
|
|
190
|
-
if (targetPage?.pptrPage?.isClosed() === false) {
|
|
191
|
-
pageUrl = targetPage.pptrPage.url();
|
|
192
|
-
}
|
|
246
|
+
pageUrl = context.getSelectedMcpPageUrl(page);
|
|
193
247
|
// Resolve data format: --experimentalDataFormat takes precedence, fall back to legacy --experimentalToonFormat
|
|
194
248
|
let dataFormat = 'default';
|
|
195
249
|
if (this.serverArgs.experimentalDataFormat) {
|
|
@@ -13,7 +13,7 @@ import { StdioServerTransport } from '../third_party/index.js';
|
|
|
13
13
|
import { checkForUpdates } from '../utils/check-for-updates.js';
|
|
14
14
|
import { logger, saveLogsToFile } from '../utils/logger.js';
|
|
15
15
|
import { VERSION } from '../version.js';
|
|
16
|
-
import {
|
|
16
|
+
import { mcpOptions, parseArguments } from '../config/mcp-options.js';
|
|
17
17
|
await checkForUpdates('Run `npm install chrome-devtools-mcp@latest` to update.');
|
|
18
18
|
export const args = parseArguments(VERSION);
|
|
19
19
|
const logFile = args.logFile ? saveLogsToFile(args.logFile) : undefined;
|
|
@@ -68,5 +68,5 @@ await server.connect(transport);
|
|
|
68
68
|
logger?.('Chrome DevTools MCP Server connected');
|
|
69
69
|
logDisclaimers(args);
|
|
70
70
|
void ClearcutLogger.get()?.logDailyActiveIfNeeded();
|
|
71
|
-
void ClearcutLogger.get()?.logServerStart(computeFlagUsage(args,
|
|
71
|
+
void ClearcutLogger.get()?.logServerStart(computeFlagUsage(args, mcpOptions));
|
|
72
72
|
//# sourceMappingURL=chrome-devtools-mcp-main.js.map
|
|
@@ -12,34 +12,26 @@ import { logDisclaimers } from '../index.js';
|
|
|
12
12
|
import { hideBin, yargs } from '../third_party/index.js';
|
|
13
13
|
import { checkForUpdates } from '../utils/check-for-updates.js';
|
|
14
14
|
import { VERSION } from '../version.js';
|
|
15
|
-
import { commands } from '
|
|
16
|
-
import {
|
|
15
|
+
import { commands } from '../config/cli-options.js';
|
|
16
|
+
import { mcpOptions, parseArguments, getMcpOptionsForViaCli, } from '../config/mcp-options.js';
|
|
17
17
|
await checkForUpdates('Run `npm install -g chrome-devtools-mcp@latest` and `chrome-devtools start` to update and restart the daemon.');
|
|
18
|
+
const DEFAULT_CLI_ARGS = ['--viaCli'];
|
|
18
19
|
async function start(args, sessionId) {
|
|
19
|
-
const combinedArgs = [...
|
|
20
|
+
const combinedArgs = [...DEFAULT_CLI_ARGS, ...args];
|
|
20
21
|
await startDaemon(combinedArgs, sessionId);
|
|
21
22
|
logDisclaimers(parseArguments(VERSION, combinedArgs));
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
};
|
|
27
|
-
// Missing CLI serialization.
|
|
28
|
-
delete
|
|
29
|
-
// Change the defaults for the CLI.
|
|
30
|
-
delete
|
|
31
|
-
delete
|
|
32
|
-
|
|
33
|
-
if (!('default' in cliOptions.headless)) {
|
|
34
|
-
throw new Error('headless cli option unexpectedly does not have a default');
|
|
24
|
+
function getCliOptions() {
|
|
25
|
+
const options = {
|
|
26
|
+
...getMcpOptionsForViaCli(),
|
|
27
|
+
};
|
|
28
|
+
// Missing CLI serialization.
|
|
29
|
+
delete options.viewport;
|
|
30
|
+
// Change the defaults for the CLI.
|
|
31
|
+
delete options.experimentalStructuredContent;
|
|
32
|
+
delete options.experimentalInteropTools;
|
|
33
|
+
return options;
|
|
35
34
|
}
|
|
36
|
-
if ('default' in cliOptions.isolated) {
|
|
37
|
-
throw new Error('isolated cli option unexpectedly has a default');
|
|
38
|
-
}
|
|
39
|
-
startCliOptions.headless.default = true;
|
|
40
|
-
startCliOptions.isolated.description =
|
|
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
|
-
startCliOptions.categoryExtensions.default = true;
|
|
43
35
|
const y = yargs(hideBin(process.argv))
|
|
44
36
|
.locale('en') // Force English to ensure error string matching works in .fail, all custom messages we output are in English anyways
|
|
45
37
|
.scriptName('chrome-devtools')
|
|
@@ -71,9 +63,9 @@ const y = yargs(hideBin(process.argv))
|
|
|
71
63
|
console.error('💡 TIP FOR AI AGENT / DEVELOPER:');
|
|
72
64
|
console.error('In the `chrome-devtools` CLI:');
|
|
73
65
|
console.error('1. Required parameters MUST be passed as positional arguments (without flags).');
|
|
74
|
-
console.error(' - INCORRECT: chrome-devtools
|
|
75
|
-
console.error(' - CORRECT: chrome-devtools
|
|
76
|
-
console.error('2. Optional parameters are passed as double-dash options/flags (e.g. --
|
|
66
|
+
console.error(' - INCORRECT: chrome-devtools click --pageId 1 --uid "1_2"');
|
|
67
|
+
console.error(' - CORRECT: chrome-devtools click 1 "1_2"');
|
|
68
|
+
console.error('2. Optional parameters are passed as double-dash options/flags (e.g. --dblClick true).');
|
|
77
69
|
console.error('3. Make sure to escape quotes properly for your shell environment.');
|
|
78
70
|
console.error('Run `chrome-devtools <command> --help` to see exact positional and optional parameters.');
|
|
79
71
|
console.error('=========================================');
|
|
@@ -85,20 +77,27 @@ const y = yargs(hideBin(process.argv))
|
|
|
85
77
|
process.exit(1);
|
|
86
78
|
});
|
|
87
79
|
y.command('start', 'Start or restart chrome-devtools-mcp', y => y
|
|
88
|
-
.options(
|
|
80
|
+
.options(getCliOptions())
|
|
89
81
|
.example('$0 start --browserUrl http://localhost:9222', 'Start the server connecting to an existing browser')
|
|
90
82
|
.strict(), async (argv) => {
|
|
91
83
|
if (isDaemonRunning(argv.sessionId)) {
|
|
92
84
|
await stopDaemon(argv.sessionId);
|
|
93
85
|
}
|
|
94
86
|
// Defaults but we do not want to affect the yargs conflict resolution.
|
|
95
|
-
if (argv.isolated === undefined &&
|
|
87
|
+
if (argv.isolated === undefined &&
|
|
88
|
+
argv.userDataDir === undefined &&
|
|
89
|
+
!argv.autoConnect &&
|
|
90
|
+
!argv.browserUrl &&
|
|
91
|
+
!argv.wsEndpoint) {
|
|
96
92
|
argv.isolated = true;
|
|
97
93
|
}
|
|
98
|
-
if (argv.headless === undefined
|
|
94
|
+
if (argv.headless === undefined &&
|
|
95
|
+
!argv.autoConnect &&
|
|
96
|
+
!argv.browserUrl &&
|
|
97
|
+
!argv.wsEndpoint) {
|
|
99
98
|
argv.headless = true;
|
|
100
99
|
}
|
|
101
|
-
const args = serializeArgs(
|
|
100
|
+
const args = serializeArgs(mcpOptions, argv);
|
|
102
101
|
await start(args, argv.sessionId);
|
|
103
102
|
process.exit(0);
|
|
104
103
|
}).strict(); // Re-enable strict validation for other commands; this is applied to the yargs instance itself
|
|
@@ -192,7 +191,7 @@ for (const [commandName, commandDef] of Object.entries(commands)) {
|
|
|
192
191
|
? verifyDaemonVersion(sessionId, VERSION)
|
|
193
192
|
: Promise.resolve(undefined);
|
|
194
193
|
if (!isDaemonRunning(sessionId)) {
|
|
195
|
-
await start(serializeArgs(
|
|
194
|
+
await start(serializeArgs(mcpOptions, argv), sessionId);
|
|
196
195
|
}
|
|
197
196
|
const commandArgs = {};
|
|
198
197
|
for (const argName of Object.keys(args)) {
|