@@ -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,82 @@ 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+ for ( const page of regularPages ) {
583+ const isolatedContextName = context . getIsolatedContextName ( page ) ;
584+ const contextLabel = isolatedContextName
585+ ? ` isolatedContext=${ isolatedContextName } `
586+ : '' ;
587+ parts . push (
588+ `${ context . getPageId ( page ) } : ${ page . url ( ) } ${ context . isPageSelected ( page ) ? ' [selected]' : '' } ${ contextLabel } ` ,
589+ ) ;
590+ }
591+ response . push ( ...parts ) ;
592+ structuredContent . pages = regularPages . map ( page => {
593+ const isolatedContextName = context . getIsolatedContextName ( page ) ;
594+ const entry : {
595+ id : number | undefined ;
596+ url : string ;
597+ selected : boolean ;
598+ isolatedContext ?: string ;
599+ } = {
600+ id : context . getPageId ( page ) ,
601+ url : page . url ( ) ,
602+ selected : context . isPageSelected ( page ) ,
603+ } ;
604+ if ( isolatedContextName ) {
605+ entry . isolatedContext = isolatedContextName ;
606+ }
607+ return entry ;
608+ } ) ;
571609 }
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 ;
610+
611+ if ( this . #includeExtensionPages) {
612+ if ( extensionPages . length ) {
613+ response . push ( `## Extension Pages` ) ;
614+ for ( const page of extensionPages ) {
615+ const isolatedContextName = context . getIsolatedContextName ( page ) ;
616+ const contextLabel = isolatedContextName
617+ ? ` isolatedContext=${ isolatedContextName } `
618+ : '' ;
619+ response . push (
620+ `${ context . getPageId ( page ) } : ${ page . url ( ) } ${ context . isPageSelected ( page ) ? ' [selected]' : '' } ${ contextLabel } ` ,
621+ ) ;
622+ }
623+ structuredContent . extensionPages = extensionPages . map ( page => {
624+ const isolatedContextName = context . getIsolatedContextName ( page ) ;
625+ const entry : {
626+ id : number | undefined ;
627+ url : string ;
628+ selected : boolean ;
629+ isolatedContext ?: string ;
630+ } = {
631+ id : context . getPageId ( page ) ,
632+ url : page . url ( ) ,
633+ selected : context . isPageSelected ( page ) ,
634+ } ;
635+ if ( isolatedContextName ) {
636+ entry . isolatedContext = isolatedContextName ;
637+ }
638+ return entry ;
639+ } ) ;
587640 }
588- return entry ;
589- } ) ;
641+ }
590642 }
591643
592644 if ( this . #includeExtensionServiceWorkers) {
0 commit comments