Skip to content

fix(tools): report closed-page navigation errors#41928

Closed
Skn0tt wants to merge 3 commits into
mainfrom
skn0tt-fix-mcp-chrome-nav-flake
Closed

fix(tools): report closed-page navigation errors#41928
Skn0tt wants to merge 3 commits into
mainfrom
skn0tt-fix-mcp-chrome-nav-flake

Conversation

@Skn0tt

@Skn0tt Skn0tt commented Jul 22, 2026

Copy link
Copy Markdown
Member

When navigation closes the page, page.goto() and page-close handling can race and produce inconsistent MCP responses.

Normalize both race orderings into an explicit navigation error, making it clear that navigation failed and the page is gone. Failed navigation no longer reports successful Playwright code execution.

Fixes the flake from #41675.

When navigating to URLs that cause Chrome to close the tab (e.g.
chrome://extensions/), page.goto() can reject with a TargetClosedError
before the context's page-close handler renders the "No open tabs"
response. This race surfaced as a ~15% flake on Windows CI.

Handle this by detecting the target-closed error combined with
page.isClosed() in the navigate catch block and returning gracefully,
letting the response builder find zero tabs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7aae2766-c0bc-47e7-a61a-5965796158a4
@Skn0tt
Skn0tt requested a review from dgozman July 22, 2026 08:32
@dgozman

dgozman commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

How come it is ok to swallow the error? I imagine client asks to navigate, and despite the page being closed we reply "everything is ok", and the next click command or something like that fails anyway. Shouldn't we respond with "failed to navigate the page" consistently, saying that not only the navigation has failed, but the whole page is gone?

Btw, I can't believe Chromium just closes the tab - there must be something else happening.

Normalize both page-close race orderings into an explicit navigation
error instead of reporting successful Playwright code execution.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7aae2766-c0bc-47e7-a61a-5965796158a4
@Skn0tt Skn0tt changed the title fix(tools): handle target-closed error in navigate for chrome:// URLs fix(tools): report closed-page navigation errors Jul 22, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7aae2766-c0bc-47e7-a61a-5965796158a4
@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

7792 passed, 1269 skipped


Merge workflow run.

@Skn0tt

Skn0tt commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

Good catch. The prior PR was totally ill-informed, the browser fully crashes and doesn't just close pages. Reverting: #41931

@Skn0tt Skn0tt closed this Jul 22, 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