File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -344,20 +344,28 @@ export class McpContext implements Context {
344344 return this . #selectedPage === page ;
345345 }
346346
347+ #maybeEmulateFocusedPage( page : Page , focused : boolean ) : void {
348+ const maybeEmulate = (
349+ page as Page & { emulateFocusedPage ?: ( focused : boolean ) => Promise < void > }
350+ ) . emulateFocusedPage ;
351+ if ( ! maybeEmulate ) {
352+ return ;
353+ }
354+ void maybeEmulate . call ( page , focused ) . catch ( error => {
355+ this . logger ( 'Error toggling focused page emulation' , error ) ;
356+ } ) ;
357+ }
358+
347359 selectPage ( newPage : Page ) : void {
348360 const oldPage = this . #selectedPage;
349361 if ( oldPage ) {
350362 oldPage . off ( 'dialog' , this . #dialogHandler) ;
351- void oldPage . emulateFocusedPage ( false ) . catch ( error => {
352- this . logger ( 'Error turning off focused page emulation' , error ) ;
353- } ) ;
363+ this . #maybeEmulateFocusedPage( oldPage , false ) ;
354364 }
355365 this . #selectedPage = newPage ;
356366 newPage . on ( 'dialog' , this . #dialogHandler) ;
357367 this . #updateSelectedPageTimeouts( ) ;
358- void newPage . emulateFocusedPage ( true ) . catch ( error => {
359- this . logger ( 'Error turning on focused page emulation' , error ) ;
360- } ) ;
368+ this . #maybeEmulateFocusedPage( newPage , true ) ;
361369 }
362370
363371 #updateSelectedPageTimeouts( ) {
You can’t perform that action at this time.
0 commit comments