Skip to content

fix(cli): avoid hanging on unresponsive tab titles#41733

Closed
pravinireri wants to merge 1 commit into
microsoft:mainfrom
pravinireri:fix/cli-unresponsive-tab-title-timeout-41714
Closed

fix(cli): avoid hanging on unresponsive tab titles#41733
pravinireri wants to merge 1 commit into
microsoft:mainfrom
pravinireri:fix/cli-unresponsive-tab-title-timeout-41714

Conversation

@pravinireri

@pravinireri pravinireri commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Prevents Playwright CLI response rendering from hanging when one attached CDP tab is discarded or unresponsive.

Why

Tab.headerSnapshot() currently waits on page.title() while building tab headers. If one tab never resolves renderer-bound calls, response rendering can block while collecting headers for all tabs, causing unrelated CLI commands to time out.

This intentionally does not change connectOverCDP initialization behavior. It only guards CLI response rendering so one unresponsive tab header cannot block unrelated commands after the connection has already succeeded.

Change

Adds a narrow timeout/catch around tab title collection so an unresponsive tab falls back to the existing empty-title path instead of blocking the whole response.

Tests

  • npm run ctest-mcp tabs.spec.ts -- --grep "unresponsive tab"
  • npm run ctest-mcp tabs.spec.ts

References #41714.

Copilot AI review requested due to automatic review settings July 10, 2026 15:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens Playwright CLI tab header rendering so it won’t hang when an attached CDP tab becomes discarded/unresponsive and never answers renderer-bound calls like page.title().

Changes:

  • Add a 5s cap around Tab.headerSnapshot() title lookup so one unresponsive tab can’t block response rendering.
  • Add an MCP test that simulates an unresponsive tab (blocked main thread) and asserts browser_tabs listing still completes and renders the tab with an empty title fallback.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/playwright-core/src/tools/backend/tab.ts Adds a timeout-guarded title collection in headerSnapshot() to prevent CLI response rendering from hanging on unresponsive tabs.
tests/mcp/tabs.spec.ts Adds coverage ensuring browser_tabs listing is not blocked by a tab whose title lookup never resolves.

// resolve the title lookup. Cap it so that one bad tab does not block
// rendering of the whole response.
let timeoutId: ReturnType<typeof setTimeout> | undefined;
const titleTimeout = new Promise<void>(resolve => timeoutId = setTimeout(resolve, 5000));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't want to rely on a timeout for this, as it would be unreliable on a slow machine, page hanging on load etc. Also it only addresses title command while any other interaction with the frozen page will lead to an error. We are going to try to find a better fix that can be applied on the browser side to help playwright reliably detect unresponsive/frozen tabs when connecting over CDP and not fail on them.

@yury-s

yury-s commented Jul 10, 2026

Copy link
Copy Markdown
Member

Closing this pr. Stay tuned for the updates in the issue.

@yury-s yury-s closed this Jul 10, 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.

3 participants