Skip to content

fix(mcp): handle page crash event in Tab constructor#40426

Open
o070256 wants to merge 2 commits intomicrosoft:mainfrom
o070256:fix/mcp-tab-crash-handler
Open

fix(mcp): handle page crash event in Tab constructor#40426
o070256 wants to merge 2 commits intomicrosoft:mainfrom
o070256:fix/mcp-tab-crash-handler

Conversation

@o070256
Copy link
Copy Markdown

@o070256 o070256 commented Apr 26, 2026

Summary

The Tab constructor registers listeners for various page events, including close, but not crash. These are two distinct Playwright events:

  • close — fired when a page is closed normally
  • crash — fired when the renderer process crashes (e.g. OOM, GPU crash, or certain unhandled conditions in complex SPAs)

When a renderer crash occurs, _onClose() is never called, leaving the tab as a zombie in the _tabs array — technically present but non-functional. Any subsequent tool call that tries to interact with the page will either hang indefinitely or fail with confusing errors like Target closed, without the MCP server properly recovering.

Change

Add a single crash event listener that calls the same _onClose() handler already used for close:

eventsHelper.addEventListener(p, 'crash', () => this._onClose()),

This ensures consistent cleanup regardless of how the page terminates.

Testing

Manually verified by navigating to a page that triggers a renderer crash — after the fix, the MCP backend correctly removes the tab and recovers on the next tool call.

The Tab constructor listens for the 'close' event to clean up state,
but not for 'crash'. A renderer crash leaves the tab as a zombie in
_tabs — technically open but non-functional. Any subsequent tool call
against it will either hang or fail with confusing errors.

Add a 'crash' listener that calls the same _onClose() handler,
ensuring consistent cleanup regardless of how the page terminates.
@Skn0tt
Copy link
Copy Markdown
Member

Skn0tt commented Apr 27, 2026

Hi, could you add a regression test for this? Look at page-event-crash.spec.ts for inspiration, a chromium-only test should suffice.

Verifies that a renderer crash removes the tab from the MCP server's
internal list and that subsequent tool calls succeed without hanging.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@o070256
Copy link
Copy Markdown
Author

o070256 commented Apr 28, 2026

@microsoft-github-policy-service agree

@Skn0tt
Copy link
Copy Markdown
Member

Skn0tt commented Apr 29, 2026

Now that I see the test, I'm not sure this is the right behaviour. When the page crashes, we want the agent to get some sort of a notification about it, not just the page to disappear. Similar to what we do in drainPendingUnhandledRejections. Could you open an issue and describe your scenario, so we can discuss how we fix it first?

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