Skip to content

fix: filter targetFilter to page-level targets to prevent connection timeouts#1109

Closed
kevmo314 wants to merge 1 commit intoChromeDevTools:mainfrom
kevmo314:fix/lazy-network-enable
Closed

fix: filter targetFilter to page-level targets to prevent connection timeouts#1109
kevmo314 wants to merge 1 commit intoChromeDevTools:mainfrom
kevmo314:fix/lazy-network-enable

Conversation

@kevmo314
Copy link
Copy Markdown

@kevmo314 kevmo314 commented Mar 5, 2026

Summary

When connecting to a browser with many open tabs via --browserUrl or --wsEndpoint, the MCP server can time out with Network.enable timed out because 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 targetFilter in makeTargetFilter() to only attach to page and other type targets. This is safe because:

  • Iframes within pages are still accessible via page.frames() — they don't need to be separate targets
  • Network/console events work through the page-level CDP session
  • Extension service workers (--categoryExtensions) are disabled by default and were already filtered out by the chrome-extension:// URL prefix filter

Before/After

With ~58 browser targets (7 pages, 24 iframes, 13 service workers, 9 workers, 4 background pages, 1 webview):

  • Before: puppeteer.connect() hangs for 180s then times out
  • After: puppeteer.connect() attaches to ~7-9 targets and completes quickly

Test plan

  • tsc --noEmit passes
  • Verify list_pages returns all open pages
  • Verify select_page + page interaction tools work
  • Verify network request listing works on selected page
  • Verify console message collection works
  • Test with --categoryExtensions to confirm extension tools still work when launched (not connected)

🤖 Generated with Claude Code

…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>
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Mar 5, 2026

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.

Comment thread src/browser.ts
]);

return function targetFilter(target: Target): boolean {
// Only attach to page-level targets. Iframes, service workers, shared
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not not true, those targets are needed.

@OrKoN
Copy link
Copy Markdown
Collaborator

OrKoN commented Mar 5, 2026

Thanks for the PR! are you sure you are not hitting this issue with frozen tabs instead #775 ?

@OrKoN
Copy link
Copy Markdown
Collaborator

OrKoN commented Mar 5, 2026

Iframes within pages are still accessible via page.frames() — they don't need to be separate targets

This is false as well.

@kevmo314
Copy link
Copy Markdown
Author

kevmo314 commented Mar 5, 2026

Thanks for the PR! are you sure you are not hitting this issue with frozen tabs instead #775 ?

Ah it's possible this is the real issue I'm hitting, thanks for the link!

@kevmo314 kevmo314 closed this Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants