Skip to content

Commit 19ce7af

Browse files
committed
fix: skip frozen/discarded targets in page enumeration
When Chrome freezes or discards background tabs, target.page() can time out on Network.enable. Calling browser.pages() lets one such target abort the entire enumeration. Replace it with a per-target iteration over browser.targets() so frozen targets are individually caught, logged, and skipped without affecting healthy pages. Fixes #1230
1 parent 582c9e0 commit 19ce7af

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

src/McpContext.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,34 @@ export class McpContext implements Context {
562562
isolatedContextNames: Map<Page, string>;
563563
}> {
564564
const defaultCtx = this.browser.defaultBrowserContext();
565-
const allPages = await this.browser.pages(
566-
this.#options.experimentalIncludeAllPages,
567-
);
568565

566+
// Enumerate targets individually instead of calling browser.pages() so
567+
// that a single frozen/discarded background tab that times out on
568+
// Network.enable cannot abort the entire page enumeration (see #1230).
569569
const allTargets = this.browser.targets();
570+
const pageTargets = allTargets.filter(target => {
571+
const type = target.type();
572+
if (type === 'page') return true;
573+
if (this.#options.experimentalIncludeAllPages) {
574+
return type === 'background_page' || type === 'webview';
575+
}
576+
return false;
577+
});
578+
const pageResults = await Promise.all(
579+
pageTargets.map(async target => {
580+
try {
581+
return await target.page();
582+
} catch (err) {
583+
this.logger(
584+
'Skipping frozen/discarded target at',
585+
target.url(),
586+
err,
587+
);
588+
return null;
589+
}
590+
}),
591+
);
592+
const allPages = pageResults.filter((p): p is Page => p !== null);
570593
const extensionTargets = allTargets.filter(target => {
571594
return (
572595
target.url().startsWith('chrome-extension://') &&

0 commit comments

Comments
 (0)