Skip to content

Commit 8f355a7

Browse files
committed
Guard emulateFocusedPage calls
1 parent b98ab37 commit 8f355a7

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/McpContext.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff 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() {

0 commit comments

Comments
 (0)