chrome-devtools-mcp 0.19.0 → 0.20.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 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
 
@@ -358,7 +358,7 @@ Alternatively, follow the <a href="https://docs.qoder.com/user-guide/chat/model-
358
358
  <details>
359
359
  <summary>Qoder CLI</summary>
360
360
 
361
- Install the Chrome DevTools MCP server using the Qoder CLI (<a href="https://docs.qoder.com/cli/using-cli#mcp-servsers">guide</a>):
361
+ Install the Chrome DevTools MCP server using the Qoder CLI (<a href="https://docs.qoder.com/cli/using-cli#mcp-servers">guide</a>):
362
362
 
363
363
  **Project wide:**
364
364
 
@@ -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) {
@@ -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
+ }