@@ -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 ,
@@ -116,7 +112,6 @@ export class McpContext implements Context {
116112 #isRunningTrace = false ;
117113 #screenRecorderData: { recorder : ScreenRecorder ; filePath : string } | null =
118114 null ;
119- #focusedPagePerContext = new Map < BrowserContext , Page > ( ) ;
120115
121116 #nextPageId = 1 ;
122117
@@ -302,10 +297,6 @@ export class McpContext implements Context {
302297 page . dispose ( ) ;
303298 this . #mcpPages. delete ( page . pptrPage ) ;
304299 }
305- const ctx = page . pptrPage . browserContext ( ) ;
306- if ( this . #focusedPagePerContext. get ( ctx ) === page . pptrPage ) {
307- this . #focusedPagePerContext. delete ( ctx ) ;
308- }
309300 await page . pptrPage . close ( { runBeforeUnload : false } ) ;
310301 }
311302
@@ -499,38 +490,9 @@ export class McpContext implements Context {
499490 return this . #selectedPage?. pptrPage === page ;
500491 }
501492
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-
516493 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 ) ;
529494 this . #selectedPage = newPage ;
530495 this . #updateSelectedPageTimeouts( ) ;
531- void newPage . pptrPage . emulateFocusedPage ( true ) . catch ( error => {
532- this . logger ( 'Error turning on focused page emulation' , error ) ;
533- } ) ;
534496 }
535497
536498 #updateSelectedPageTimeouts( ) {
@@ -606,6 +568,10 @@ export class McpContext implements Context {
606568 if ( ! mcpPage ) {
607569 mcpPage = new McpPage ( page , this . #nextPageId++ ) ;
608570 this . #mcpPages. set ( page , mcpPage ) ;
571+ // We emulate a focused page for all pages to support multi-agent workflows.
572+ void page . emulateFocusedPage ( true ) . catch ( error => {
573+ this . logger ( 'Error turning on focused page emulation' , error ) ;
574+ } ) ;
609575 }
610576 mcpPage . isolatedContextName = isolatedContextNames . get ( page ) ;
611577 }
@@ -618,12 +584,6 @@ export class McpContext implements Context {
618584 this . #mcpPages. delete ( page ) ;
619585 }
620586 }
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- }
627587
628588 this . #pages = allPages . filter ( page => {
629589 return (
0 commit comments