@@ -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 = [ ] ;
@@ -559,34 +563,54 @@ Call ${handleDialog.name} to handle it before continuing.`);
559563 }
560564
561565 if ( this . #includePages) {
562- const parts = [ `## Pages` ] ;
563- for ( const page of context . getPages ( ) ) {
564- const isolatedContextName = context . getIsolatedContextName ( page ) ;
565- const contextLabel = isolatedContextName
566- ? ` isolatedContext=${ isolatedContextName } `
567- : '' ;
568- parts . push (
569- `${ context . getPageId ( page ) } : ${ page . url ( ) } ${ context . isPageSelected ( page ) ? ' [selected]' : '' } ${ contextLabel } ` ,
570- ) ;
566+ const allPages = context . getPages ( ) ;
567+
568+ const { regularPages, extensionPages} = allPages . reduce (
569+ ( acc : { regularPages : Page [ ] ; extensionPages : Page [ ] } , page : Page ) => {
570+ if ( page . url ( ) . startsWith ( 'chrome-extension://' ) ) {
571+ acc . extensionPages . push ( page ) ;
572+ } else {
573+ acc . regularPages . push ( page ) ;
574+ }
575+ return acc ;
576+ } ,
577+ { regularPages : [ ] , extensionPages : [ ] } ,
578+ ) ;
579+
580+ if ( regularPages . length ) {
581+ const parts = [ `## Pages` ] ;
582+ const structuredPages = [ ] ;
583+ for ( const page of regularPages ) {
584+ const isolatedContextName = context . getIsolatedContextName ( page ) ;
585+ const contextLabel = isolatedContextName
586+ ? ` isolatedContext=${ isolatedContextName } `
587+ : '' ;
588+ parts . push (
589+ `${ context . getPageId ( page ) } : ${ page . url ( ) } ${ context . isPageSelected ( page ) ? ' [selected]' : '' } ${ contextLabel } ` ,
590+ ) ;
591+ structuredPages . push ( createStructuredPage ( page , context ) ) ;
592+ }
593+ response . push ( ...parts ) ;
594+ structuredContent . pages = structuredPages ;
571595 }
572- response . push ( ...parts ) ;
573- structuredContent . pages = context . getPages ( ) . map ( page => {
574- const isolatedContextName = context . getIsolatedContextName ( page ) ;
575- const entry : {
576- id : number | undefined ;
577- url : string ;
578- selected : boolean ;
579- isolatedContext ?: string ;
580- } = {
581- id : context . getPageId ( page ) ,
582- url : page . url ( ) ,
583- selected : context . isPageSelected ( page ) ,
584- } ;
585- if ( isolatedContextName ) {
586- entry . isolatedContext = isolatedContextName ;
596+
597+ if ( this . #includeExtensionPages) {
598+ if ( extensionPages . length ) {
599+ response . push ( `## Extension Pages` ) ;
600+ const structuredExtensionPages = [ ] ;
601+ for ( const page of extensionPages ) {
602+ const isolatedContextName = context . getIsolatedContextName ( page ) ;
603+ const contextLabel = isolatedContextName
604+ ? ` isolatedContext=${ isolatedContextName } `
605+ : '' ;
606+ response . push (
607+ `${ context . getPageId ( page ) } : ${ page . url ( ) } ${ context . isPageSelected ( page ) ? ' [selected]' : '' } ${ contextLabel } ` ,
608+ ) ;
609+ structuredExtensionPages . push ( createStructuredPage ( page , context ) ) ;
610+ }
611+ structuredContent . extensionPages = structuredExtensionPages ;
587612 }
588- return entry ;
589- } ) ;
613+ }
590614 }
591615
592616 if ( this . #includeExtensionServiceWorkers) {
@@ -803,3 +827,21 @@ Call ${handleDialog.name} to handle it before continuing.`);
803827 this . #textResponseLines = [ ] ;
804828 }
805829}
830+ function createStructuredPage ( page : Page , context : McpContext ) {
831+ const isolatedContextName = context . getIsolatedContextName ( page ) ;
832+ const entry : {
833+ id : number | undefined ;
834+ url : string ;
835+ selected : boolean ;
836+ isolatedContext ?: string ;
837+ } = {
838+ id : context . getPageId ( page ) ,
839+ url : page . url ( ) ,
840+ selected : context . isPageSelected ( page ) ,
841+ } ;
842+ if ( isolatedContextName ) {
843+ entry . isolatedContext = isolatedContextName ;
844+ }
845+ return entry ;
846+ }
847+
0 commit comments