fix: filter targetFilter to page-level targets to prevent connection timeouts#1109
fix: filter targetFilter to page-level targets to prevent connection timeouts#1109kevmo314 wants to merge 1 commit intoChromeDevTools:mainfrom
Conversation
…tion 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>
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
| ]); | ||
|
|
||
| return function targetFilter(target: Target): boolean { | ||
| // Only attach to page-level targets. Iframes, service workers, shared |
There was a problem hiding this comment.
this is not not true, those targets are needed.
|
Thanks for the PR! are you sure you are not hitting this issue with frozen tabs instead #775 ? |
This is false as well. |
Ah it's possible this is the real issue I'm hitting, thanks for the link! |
Summary
When connecting to a browser with many open tabs via
--browserUrlor--wsEndpoint, the MCP server can time out withNetwork.enable timed outbecause 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 background tabs don't respond to these commands, causing the connection to hang until the protocol timeout (180s) is reached. A typical browsing session can easily have 50-60+ targets but only ~7 actual pages.
Fix
Restricts
targetFilterinmakeTargetFilter()to only attach topageandothertype targets. This is safe because:page.frames()— they don't need to be separate targets--categoryExtensions) are disabled by default and were already filtered out by thechrome-extension://URL prefix filterBefore/After
With ~58 browser targets (7 pages, 24 iframes, 13 service workers, 9 workers, 4 background pages, 1 webview):
puppeteer.connect()hangs for 180s then times outpuppeteer.connect()attaches to ~7-9 targets and completes quicklyTest plan
tsc --noEmitpasseslist_pagesreturns all open pagesselect_page+ page interaction tools work--categoryExtensionsto confirm extension tools still work when launched (not connected)🤖 Generated with Claude Code