chrome-devtools-mcp 0.19.0 → 0.20.1

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 CHANGED
@@ -122,7 +122,7 @@ To use the Chrome DevTools MCP server follow the instructions from <a href="http
122
122
 
123
123
  This will make the Chrome DevTools MCP server automatically connect to the browser that Antigravity is using. If you are not using port 9222, make sure to adjust accordingly.
124
124
 
125
- Chrome DevTools MCP will not start the browser instance automatically using this approach as as the Chrome DevTools MCP server runs in Antigravity's built-in browser. If the browser is not already running, you have to start it first by clicking the Chrome icon at the top right corner.
125
+ Chrome DevTools MCP will not start the browser instance automatically using this approach because the Chrome DevTools MCP server connects to Antigravity's built-in browser. If the browser is not already running, you have to start it first by clicking the Chrome icon at the top right corner.
126
126
 
127
127
  </details>
128
128
 
@@ -228,10 +228,18 @@ Configure the following fields and press `CTRL+S` to save the configuration:
228
228
  Follow the MCP install <a href="https://code.visualstudio.com/docs/copilot/chat/mcp-servers#_add-an-mcp-server">guide</a>,
229
229
  with the standard config from above. You can also install the Chrome DevTools MCP server using the VS Code CLI:
230
230
 
231
+ For macOS and Linux:
232
+
231
233
  ```bash
232
234
  code --add-mcp '{"name":"io.github.ChromeDevTools/chrome-devtools-mcp","command":"npx","args":["-y","chrome-devtools-mcp"],"env":{}}'
233
235
  ```
234
236
 
237
+ For Windows (PowerShell):
238
+
239
+ ```powershell
240
+ code --add-mcp '{"""name""":"""io.github.ChromeDevTools/chrome-devtools-mcp""","""command""":"""npx""","""args""":["""-y""","""chrome-devtools-mcp"""]}'
241
+ ```
242
+
235
243
  </details>
236
244
 
237
245
  <details>
@@ -358,7 +366,7 @@ Alternatively, follow the <a href="https://docs.qoder.com/user-guide/chat/model-
358
366
  <details>
359
367
  <summary>Qoder CLI</summary>
360
368
 
361
- Install the Chrome DevTools MCP server using the Qoder CLI (<a href="https://docs.qoder.com/cli/using-cli#mcp-servsers">guide</a>):
369
+ Install the Chrome DevTools MCP server using the Qoder CLI (<a href="https://docs.qoder.com/cli/using-cli#mcp-servers">guide</a>):
362
370
 
363
371
  **Project wide:**
364
372
 
@@ -6,52 +6,6 @@
6
6
  import { PuppeteerDevToolsConnection } from './DevToolsConnectionAdapter.js';
7
7
  import { Mutex } from './Mutex.js';
8
8
  import { DevTools } from './third_party/index.js';
9
- export function extractUrlLikeFromDevToolsTitle(title) {
10
- const match = title.match(new RegExp(`DevTools - (.*)`));
11
- return match?.[1] ?? undefined;
12
- }
13
- export function urlsEqual(url1, url2) {
14
- const normalizedUrl1 = normalizeUrl(url1);
15
- const normalizedUrl2 = normalizeUrl(url2);
16
- return normalizedUrl1 === normalizedUrl2;
17
- }
18
- /**
19
- * For the sake of the MCP server, when we determine if two URLs are equal we
20
- * remove some parts:
21
- *
22
- * 1. We do not care about the protocol.
23
- * 2. We do not care about trailing slashes.
24
- * 3. We do not care about "www".
25
- * 4. We ignore the hash parts.
26
- *
27
- * For example, if the user types "record a trace on foo.com", we would want to
28
- * match a tab in the connected Chrome instance that is showing "www.foo.com/"
29
- */
30
- function normalizeUrl(url) {
31
- let result = url.trim();
32
- // Remove protocols
33
- if (result.startsWith('https://')) {
34
- result = result.slice(8);
35
- }
36
- else if (result.startsWith('http://')) {
37
- result = result.slice(7);
38
- }
39
- // Remove 'www.'. This ensures that we find the right URL regardless of if the user adds `www` or not.
40
- if (result.startsWith('www.')) {
41
- result = result.slice(4);
42
- }
43
- // We use target URLs to locate DevTools but those often do
44
- // no include hash.
45
- const hashIdx = result.lastIndexOf('#');
46
- if (hashIdx !== -1) {
47
- result = result.slice(0, hashIdx);
48
- }
49
- // Remove trailing slash
50
- if (result.endsWith('/')) {
51
- result = result.slice(0, -1);
52
- }
53
- return result;
54
- }
55
9
  /**
56
10
  * A mock implementation of an issues manager that only implements the methods
57
11
  * that are actually used by the IssuesAggregator
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import fs from 'node:fs/promises';
7
7
  import path from 'node:path';
8
- import { extractUrlLikeFromDevToolsTitle, UniverseManager, urlsEqual, } from './DevtoolsUtils.js';
8
+ import { UniverseManager } from './DevtoolsUtils.js';
9
9
  import { McpPage } from './McpPage.js';
10
10
  import { NetworkCollector, ConsoleCollector } from './PageCollector.js';
11
11
  import { Locator } from './third_party/index.js';
@@ -49,6 +49,7 @@ export class McpContext {
49
49
  #isRunningTrace = false;
50
50
  #screenRecorderData = null;
51
51
  #nextPageId = 1;
52
+ #extensionPages = new WeakMap();
52
53
  #extensionServiceWorkerMap = new WeakMap();
53
54
  #nextExtensionServiceWorkerId = 1;
54
55
  #nextSnapshotId = 1;
@@ -411,6 +412,32 @@ export class McpContext {
411
412
  async #getAllPages() {
412
413
  const defaultCtx = this.browser.defaultBrowserContext();
413
414
  const allPages = await this.browser.pages(this.#options.experimentalIncludeAllPages);
415
+ const allTargets = this.browser.targets();
416
+ const extensionTargets = allTargets.filter(target => {
417
+ return (target.url().startsWith('chrome-extension://') &&
418
+ target.type() === 'page');
419
+ });
420
+ for (const target of extensionTargets) {
421
+ // Right now target.page() returns null for popup and side panel pages.
422
+ let page = await target.page();
423
+ if (!page) {
424
+ // We need to cache pages instances for targets because target.asPage()
425
+ // returns a new page instance every time.
426
+ page = this.#extensionPages.get(target) ?? null;
427
+ if (!page) {
428
+ try {
429
+ page = await target.asPage();
430
+ this.#extensionPages.set(target, page);
431
+ }
432
+ catch (e) {
433
+ this.logger('Failed to get page for extension target', e);
434
+ }
435
+ }
436
+ }
437
+ if (page && !allPages.includes(page)) {
438
+ allPages.push(page);
439
+ }
440
+ }
414
441
  // Build a reverse lookup from BrowserContext instance → name.
415
442
  const contextToName = new Map();
416
443
  for (const [name, ctx] of this.#isolatedContexts) {
@@ -440,38 +467,18 @@ export class McpContext {
440
467
  async detectOpenDevToolsWindows() {
441
468
  this.logger('Detecting open DevTools windows');
442
469
  const { pages } = await this.#getAllPages();
443
- // Clear all devToolsPage references before re-detecting.
444
- for (const mcpPage of this.#mcpPages.values()) {
445
- mcpPage.devToolsPage = undefined;
446
- }
447
- for (const devToolsPage of pages) {
448
- if (devToolsPage.url().startsWith('devtools://')) {
449
- try {
450
- this.logger('Calling getTargetInfo for ' + devToolsPage.url());
451
- const data = await devToolsPage
452
- // @ts-expect-error no types for _client().
453
- ._client()
454
- .send('Target.getTargetInfo');
455
- const devtoolsPageTitle = data.targetInfo.title;
456
- const urlLike = extractUrlLikeFromDevToolsTitle(devtoolsPageTitle);
457
- if (!urlLike) {
458
- continue;
459
- }
460
- // TODO: lookup without a loop.
461
- for (const page of this.#pages) {
462
- if (urlsEqual(page.url(), urlLike)) {
463
- const mcpPage = this.#mcpPages.get(page);
464
- if (mcpPage) {
465
- mcpPage.devToolsPage = devToolsPage;
466
- }
467
- }
468
- }
469
- }
470
- catch (error) {
471
- this.logger('Issue occurred while trying to find DevTools', error);
472
- }
470
+ await Promise.all(pages.map(async (page) => {
471
+ const mcpPage = this.#mcpPages.get(page);
472
+ if (!mcpPage) {
473
+ return;
473
474
  }
474
- }
475
+ if (await page.hasDevTools()) {
476
+ mcpPage.devToolsPage = await page.openDevTools();
477
+ }
478
+ else {
479
+ mcpPage.devToolsPage = undefined;
480
+ }
481
+ }));
475
482
  }
476
483
  getExtensionServiceWorkers() {
477
484
  return this.#extensionServiceWorkers;
@@ -15,6 +15,7 @@ import { paginate } from './utils/pagination.js';
15
15
  export class McpResponse {
16
16
  #includePages = false;
17
17
  #includeExtensionServiceWorkers = false;
18
+ #includeExtensionPages = false;
18
19
  #snapshotParams;
19
20
  #attachedNetworkRequestId;
20
21
  #attachedNetworkRequestOptions;
@@ -47,6 +48,7 @@ export class McpResponse {
47
48
  this.#includePages = value;
48
49
  if (this.#args.categoryExtensions) {
49
50
  this.#includeExtensionServiceWorkers = value;
51
+ this.#includeExtensionPages = value;
50
52
  }
51
53
  }
52
54
  includeSnapshot(params) {
@@ -358,27 +360,45 @@ Call ${handleDialog.name} to handle it before continuing.`);
358
360
  };
359
361
  }
360
362
  if (this.#includePages) {
361
- const parts = [`## Pages`];
362
- for (const page of context.getPages()) {
363
- const isolatedContextName = context.getIsolatedContextName(page);
364
- const contextLabel = isolatedContextName
365
- ? ` isolatedContext=${isolatedContextName}`
366
- : '';
367
- parts.push(`${context.getPageId(page)}: ${page.url()}${context.isPageSelected(page) ? ' [selected]' : ''}${contextLabel}`);
363
+ const allPages = context.getPages();
364
+ const { regularPages, extensionPages } = allPages.reduce((acc, page) => {
365
+ if (page.url().startsWith('chrome-extension://')) {
366
+ acc.extensionPages.push(page);
367
+ }
368
+ else {
369
+ acc.regularPages.push(page);
370
+ }
371
+ return acc;
372
+ }, { regularPages: [], extensionPages: [] });
373
+ if (regularPages.length) {
374
+ const parts = [`## Pages`];
375
+ const structuredPages = [];
376
+ for (const page of regularPages) {
377
+ const isolatedContextName = context.getIsolatedContextName(page);
378
+ const contextLabel = isolatedContextName
379
+ ? ` isolatedContext=${isolatedContextName}`
380
+ : '';
381
+ parts.push(`${context.getPageId(page)}: ${page.url()}${context.isPageSelected(page) ? ' [selected]' : ''}${contextLabel}`);
382
+ structuredPages.push(createStructuredPage(page, context));
383
+ }
384
+ response.push(...parts);
385
+ structuredContent.pages = structuredPages;
368
386
  }
369
- response.push(...parts);
370
- structuredContent.pages = context.getPages().map(page => {
371
- const isolatedContextName = context.getIsolatedContextName(page);
372
- const entry = {
373
- id: context.getPageId(page),
374
- url: page.url(),
375
- selected: context.isPageSelected(page),
376
- };
377
- if (isolatedContextName) {
378
- entry.isolatedContext = isolatedContextName;
387
+ if (this.#includeExtensionPages) {
388
+ if (extensionPages.length) {
389
+ response.push(`## Extension Pages`);
390
+ const structuredExtensionPages = [];
391
+ for (const page of extensionPages) {
392
+ const isolatedContextName = context.getIsolatedContextName(page);
393
+ const contextLabel = isolatedContextName
394
+ ? ` isolatedContext=${isolatedContextName}`
395
+ : '';
396
+ response.push(`${context.getPageId(page)}: ${page.url()}${context.isPageSelected(page) ? ' [selected]' : ''}${contextLabel}`);
397
+ structuredExtensionPages.push(createStructuredPage(page, context));
398
+ }
399
+ structuredContent.extensionPages = structuredExtensionPages;
379
400
  }
380
- return entry;
381
- });
401
+ }
382
402
  }
383
403
  if (this.#includeExtensionServiceWorkers) {
384
404
  if (context.getExtensionServiceWorkers().length) {
@@ -560,3 +580,15 @@ Call ${handleDialog.name} to handle it before continuing.`);
560
580
  this.#textResponseLines = [];
561
581
  }
562
582
  }
583
+ function createStructuredPage(page, context) {
584
+ const isolatedContextName = context.getIsolatedContextName(page);
585
+ const entry = {
586
+ id: context.getPageId(page),
587
+ url: page.url(),
588
+ selected: context.isPageSelected(page),
589
+ };
590
+ if (isolatedContextName) {
591
+ entry.isolatedContext = isolatedContextName;
592
+ }
593
+ return entry;
594
+ }