Skip to content

Commit 9a1836a

Browse files
kevmo314claude
andcommitted
fix: filter targetFilter to page-level targets only to prevent connection timeouts
When connecting to a browser with many tabs, Puppeteer attaches to every target (iframes, service workers, shared workers, webviews, background pages) and sends CDP initialization commands (Network.enable, Page.enable, Runtime.enable, etc.) to each one. Frozen or suspended targets don't respond to these commands, causing the connection to hang until the protocol timeout is reached. With a typical browsing session of ~60 targets (but only ~7 actual pages), this makes the MCP server unusable without first closing most tabs. The fix restricts targetFilter to only attach to 'page' and 'other' type targets. Iframes within pages remain accessible via page.frames(), and network/console events still work through the page-level CDP session. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bdbbc84 commit 9a1836a

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/browser.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ function makeTargetFilter() {
2828
]);
2929

3030
return function targetFilter(target: Target): boolean {
31+
// Only attach to page-level targets. Iframes, service workers, shared
32+
// workers, webviews, and background pages are not needed for MCP page
33+
// interactions and attempting to initialize them (Network.enable, etc.)
34+
// on frozen or suspended targets can cause connection timeouts.
35+
const type = target.type();
36+
if (type !== 'page' && type !== 'other') {
37+
return false;
38+
}
3139
if (target.url() === 'chrome://newtab/') {
3240
return true;
3341
}

0 commit comments

Comments
 (0)