From 9a1836a75128eab219f90a725825a9dd419560ed Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Thu, 5 Mar 2026 02:50:54 -0500 Subject: [PATCH] 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 --- src/browser.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/browser.ts b/src/browser.ts index 1b8cc1645..96d409072 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -28,6 +28,14 @@ function makeTargetFilter() { ]); return function targetFilter(target: Target): boolean { + // Only attach to page-level targets. Iframes, service workers, shared + // workers, webviews, and background pages are not needed for MCP page + // interactions and attempting to initialize them (Network.enable, etc.) + // on frozen or suspended targets can cause connection timeouts. + const type = target.type(); + if (type !== 'page' && type !== 'other') { + return false; + } if (target.url() === 'chrome://newtab/') { return true; }