@@ -116,7 +116,6 @@ export class McpContext implements Context {
116116 #isRunningTrace = false ;
117117 #screenRecorderData: { recorder : ScreenRecorder ; filePath : string } | null =
118118 null ;
119- #focusedPagePerContext = new Map < BrowserContext , Page > ( ) ;
120119
121120 #nextPageId = 1 ;
122121
@@ -302,10 +301,6 @@ export class McpContext implements Context {
302301 page . dispose ( ) ;
303302 this . #mcpPages. delete ( page . pptrPage ) ;
304303 }
305- const ctx = page . pptrPage . browserContext ( ) ;
306- if ( this . #focusedPagePerContext. get ( ctx ) === page . pptrPage ) {
307- this . #focusedPagePerContext. delete ( ctx ) ;
308- }
309304 await page . pptrPage . close ( { runBeforeUnload : false } ) ;
310305 }
311306
@@ -499,38 +494,9 @@ export class McpContext implements Context {
499494 return this . #selectedPage?. pptrPage === page ;
500495 }
501496
502- assertPageIsFocused ( pageToCheck : Page | ContextPage ) : void {
503- const page = 'pptrPage' in pageToCheck ? pageToCheck . pptrPage : pageToCheck ;
504- const ctx = page . browserContext ( ) ;
505- const focused = this . #focusedPagePerContext. get ( ctx ) ;
506- if ( focused && focused !== page ) {
507- const targetId = this . #mcpPages. get ( page ) ?. id ?? '?' ;
508- const focusedId = this . #mcpPages. get ( focused ) ?. id ?? '?' ;
509- throw new Error (
510- `Page ${ targetId } is not the active page in its browser context (page ${ focusedId } is). ` +
511- `Call select_page with pageId ${ targetId } first.` ,
512- ) ;
513- }
514- }
515-
516497 selectPage ( newPage : McpPage ) : void {
517- const ctx = newPage . pptrPage . browserContext ( ) ;
518- const oldFocused = this . #focusedPagePerContext. get ( ctx ) ;
519- if (
520- oldFocused &&
521- oldFocused !== newPage . pptrPage &&
522- ! oldFocused . isClosed ( )
523- ) {
524- void oldFocused . emulateFocusedPage ( false ) . catch ( error => {
525- this . logger ( 'Error turning off focused page emulation' , error ) ;
526- } ) ;
527- }
528- this . #focusedPagePerContext. set ( ctx , newPage . pptrPage ) ;
529498 this . #selectedPage = newPage ;
530499 this . #updateSelectedPageTimeouts( ) ;
531- void newPage . pptrPage . emulateFocusedPage ( true ) . catch ( error => {
532- this . logger ( 'Error turning on focused page emulation' , error ) ;
533- } ) ;
534500 }
535501
536502 #updateSelectedPageTimeouts( ) {
@@ -606,6 +572,10 @@ export class McpContext implements Context {
606572 if ( ! mcpPage ) {
607573 mcpPage = new McpPage ( page , this . #nextPageId++ ) ;
608574 this . #mcpPages. set ( page , mcpPage ) ;
575+ // We emulate a focused page for all pages to support multi-agent workflows.
576+ void page . emulateFocusedPage ( true ) . catch ( error => {
577+ this . logger ( 'Error turning on focused page emulation' , error ) ;
578+ } ) ;
609579 }
610580 mcpPage . isolatedContextName = isolatedContextNames . get ( page ) ;
611581 }
@@ -618,12 +588,6 @@ export class McpContext implements Context {
618588 this . #mcpPages. delete ( page ) ;
619589 }
620590 }
621- // Prune stale #focusedPagePerContext entries.
622- for ( const [ ctx , page ] of this . #focusedPagePerContext) {
623- if ( ! currentPages . has ( page ) ) {
624- this . #focusedPagePerContext. delete ( ctx ) ;
625- }
626- }
627591
628592 this . #pages = allPages . filter ( page => {
629593 return (
0 commit comments