@@ -16,6 +16,7 @@ import {DevTools} from './third_party/index.js';
1616import type {
1717 ConsoleMessage ,
1818 ImageContent ,
19+ Page ,
1920 ResourceType ,
2021 TextContent ,
2122} from './third_party/index.js' ;
@@ -42,6 +43,7 @@ interface TraceInsightData {
4243export class McpResponse implements Response {
4344 #includePages = false ;
4445 #includeExtensionServiceWorkers = false ;
46+ #includeExtensionPages = false ;
4547 #snapshotParams?: SnapshotParams ;
4648 #attachedNetworkRequestId?: number ;
4749 #attachedNetworkRequestOptions?: {
@@ -94,6 +96,7 @@ export class McpResponse implements Response {
9496
9597 if ( this . #args. categoryExtensions ) {
9698 this . #includeExtensionServiceWorkers = value ;
99+ this . #includeExtensionPages = value ;
97100 }
98101 }
99102
@@ -501,6 +504,7 @@ export class McpResponse implements Response {
501504 pages ?: object [ ] ;
502505 pagination ?: object ;
503506 extensionServiceWorkers ?: object [ ] ;
507+ extensionPages ?: object [ ] ;
504508 } = { } ;
505509
506510 const response = [ `# ${ toolName } response` ] ;
@@ -564,34 +568,68 @@ Call ${handleDialog.name} to handle it before continuing.`);
564568 }
565569
566570 if ( this . #includePages) {
567- const parts = [ `## Pages` ] ;
568- for ( const page of context . getPages ( ) ) {
569- const isolatedContextName = context . getIsolatedContextName ( page ) ;
570- const contextLabel = isolatedContextName
571- ? ` isolatedContext=${ isolatedContextName } `
572- : '' ;
573- parts . push (
574- `${ context . getPageId ( page ) } : ${ page . url ( ) } ${ context . isPageSelected ( page ) ? ' [selected]' : '' } ${ contextLabel } ` ,
575- ) ;
571+ const allPages = context . getPages ( ) ;
572+
573+ const { regularPages, extensionPages} = allPages . reduce (
574+ ( acc : { regularPages : Page [ ] ; extensionPages : Page [ ] } , page : Page ) => {
575+ if ( page . url ( ) . startsWith ( 'chrome-extension://' ) ) {
576+ acc . extensionPages . push ( page ) ;
577+ } else {
578+ acc . regularPages . push ( page ) ;
579+ }
580+ return acc ;
581+ } ,
582+ { regularPages : [ ] , extensionPages : [ ] } ,
583+ ) ;
584+
585+ if ( regularPages . length ) {
586+ const parts = [ `## Pages` ] ;
587+ for ( const page of regularPages ) {
588+ const isolatedContextName = context . getIsolatedContextName ( page ) ;
589+ const contextLabel = isolatedContextName
590+ ? ` isolatedContext=${ isolatedContextName } `
591+ : '' ;
592+ parts . push (
593+ `${ context . getPageId ( page ) } : ${ page . url ( ) } ${ context . isPageSelected ( page ) ? ' [selected]' : '' } ${ contextLabel } ` ,
594+ ) ;
595+ }
596+ response . push ( ...parts ) ;
597+ structuredContent . pages = regularPages . map ( page => {
598+ const isolatedContextName = context . getIsolatedContextName ( page ) ;
599+ const entry : {
600+ id : number | undefined ;
601+ url : string ;
602+ selected : boolean ;
603+ isolatedContext ?: string ;
604+ } = {
605+ id : context . getPageId ( page ) ,
606+ url : page . url ( ) ,
607+ selected : context . isPageSelected ( page ) ,
608+ } ;
609+ if ( isolatedContextName ) {
610+ entry . isolatedContext = isolatedContextName ;
611+ }
612+ return entry ;
613+ } ) ;
576614 }
577- response . push ( ...parts ) ;
578- structuredContent . pages = context . getPages ( ) . map ( page => {
579- const isolatedContextName = context . getIsolatedContextName ( page ) ;
580- const entry : {
581- id : number | undefined ;
582- url : string ;
583- selected : boolean ;
584- isolatedContext ?: string ;
585- } = {
586- id : context . getPageId ( page ) ,
587- url : page . url ( ) ,
588- selected : context . isPageSelected ( page ) ,
589- } ;
590- if ( isolatedContextName ) {
591- entry . isolatedContext = isolatedContextName ;
615+
616+ if ( this . #includeExtensionPages) {
617+ if ( extensionPages . length ) {
618+ response . push ( `## Extension Pages` ) ;
619+ for ( const page of extensionPages ) {
620+ response . push (
621+ `${ context . getPageId ( page ) } : ${ page . url ( ) } ${ context . isPageSelected ( page ) ? ' [selected]' : '' } ` ,
622+ ) ;
623+ }
624+ structuredContent . extensionPages = extensionPages . map ( page => {
625+ return {
626+ id : context . getPageId ( page ) ,
627+ url : page . url ( ) ,
628+ selected : context . isPageSelected ( page ) ,
629+ } ;
630+ } ) ;
592631 }
593- return entry ;
594- } ) ;
632+ }
595633 }
596634
597635 if ( this . #includeExtensionServiceWorkers) {
0 commit comments