@@ -34,11 +34,7 @@ import {Locator} from './third_party/index.js';
3434import { PredefinedNetworkConditions } from './third_party/index.js' ;
3535import { listPages } from './tools/pages.js' ;
3636import { CLOSE_PAGE_ERROR } from './tools/ToolDefinition.js' ;
37- import type {
38- Context ,
39- DevToolsData ,
40- ContextPage ,
41- } from './tools/ToolDefinition.js' ;
37+ import type { Context , DevToolsData } from './tools/ToolDefinition.js' ;
4238import type { TraceResult } from './trace-processing/parse.js' ;
4339import type {
4440 EmulationSettings ,
@@ -111,7 +107,6 @@ export class McpContext implements Context {
111107 #isRunningTrace = false ;
112108 #screenRecorderData: { recorder : ScreenRecorder ; filePath : string } | null =
113109 null ;
114- #focusedPagePerContext = new Map < BrowserContext , Page > ( ) ;
115110
116111 #nextPageId = 1 ;
117112
@@ -297,10 +292,6 @@ export class McpContext implements Context {
297292 page . dispose ( ) ;
298293 this . #mcpPages. delete ( page . pptrPage ) ;
299294 }
300- const ctx = page . pptrPage . browserContext ( ) ;
301- if ( this . #focusedPagePerContext. get ( ctx ) === page . pptrPage ) {
302- this . #focusedPagePerContext. delete ( ctx ) ;
303- }
304295 await page . pptrPage . close ( { runBeforeUnload : false } ) ;
305296 }
306297
@@ -494,38 +485,9 @@ export class McpContext implements Context {
494485 return this . #selectedPage?. pptrPage === page ;
495486 }
496487
497- assertPageIsFocused ( pageToCheck : Page | ContextPage ) : void {
498- const page = 'pptrPage' in pageToCheck ? pageToCheck . pptrPage : pageToCheck ;
499- const ctx = page . browserContext ( ) ;
500- const focused = this . #focusedPagePerContext. get ( ctx ) ;
501- if ( focused && focused !== page ) {
502- const targetId = this . #mcpPages. get ( page ) ?. id ?? '?' ;
503- const focusedId = this . #mcpPages. get ( focused ) ?. id ?? '?' ;
504- throw new Error (
505- `Page ${ targetId } is not the active page in its browser context (page ${ focusedId } is). ` +
506- `Call select_page with pageId ${ targetId } first.` ,
507- ) ;
508- }
509- }
510-
511488 selectPage ( newPage : McpPage ) : void {
512- const ctx = newPage . pptrPage . browserContext ( ) ;
513- const oldFocused = this . #focusedPagePerContext. get ( ctx ) ;
514- if (
515- oldFocused &&
516- oldFocused !== newPage . pptrPage &&
517- ! oldFocused . isClosed ( )
518- ) {
519- void oldFocused . emulateFocusedPage ( false ) . catch ( error => {
520- this . logger ( 'Error turning off focused page emulation' , error ) ;
521- } ) ;
522- }
523- this . #focusedPagePerContext. set ( ctx , newPage . pptrPage ) ;
524489 this . #selectedPage = newPage ;
525490 this . #updateSelectedPageTimeouts( ) ;
526- void newPage . pptrPage . emulateFocusedPage ( true ) . catch ( error => {
527- this . logger ( 'Error turning on focused page emulation' , error ) ;
528- } ) ;
529491 }
530492
531493 #updateSelectedPageTimeouts( ) {
@@ -601,6 +563,10 @@ export class McpContext implements Context {
601563 if ( ! mcpPage ) {
602564 mcpPage = new McpPage ( page , this . #nextPageId++ ) ;
603565 this . #mcpPages. set ( page , mcpPage ) ;
566+ // We emulate a focused page for all pages to support multi-agent workflows.
567+ void page . emulateFocusedPage ( true ) . catch ( error => {
568+ this . logger ( 'Error turning on focused page emulation' , error ) ;
569+ } ) ;
604570 }
605571 mcpPage . isolatedContextName = isolatedContextNames . get ( page ) ;
606572 }
@@ -613,12 +579,6 @@ export class McpContext implements Context {
613579 this . #mcpPages. delete ( page ) ;
614580 }
615581 }
616- // Prune stale #focusedPagePerContext entries.
617- for ( const [ ctx , page ] of this . #focusedPagePerContext) {
618- if ( ! currentPages . has ( page ) ) {
619- this . #focusedPagePerContext. delete ( ctx ) ;
620- }
621- }
622582
623583 this . #pages = allPages . filter ( page => {
624584 return (
0 commit comments