Skip to content

Chrome DevTools MCP gets stuck after the selected page is closed #2033

Closed

Description

@yuzhanglong

Description of the bug

Summary

When the currently selected page is closed, the Chrome DevTools MCP session can become unusable.

After that happens, MCP keeps returning:

Error: The selected page has been closed. Call list_pages to see open pages.

The problem is that recovery commands such as list_pages, new_page, and select_page may also fail with the same error, so the session cannot recover even though the browser still has other open pages.

Environment

  • Chrome DevTools MCP
  • Remote debugging against Android Chrome
  • Remote browser discovered through browser_url=http://127.0.0.1:9223
  • The remote browser was still alive and still had open pages after the failure

Reproduction Steps

  1. Connect Chrome DevTools MCP to a remote Android Chrome instance.
  2. Open multiple pages so that MCP has an active selected page.
  3. Close the currently selected page.
    • This may happen because of page logic, host behavior, user action, or any other normal page lifecycle.
  4. Try any MCP page-management command afterwards, such as:
    • list_pages
    • new_page
    • select_page

Actual Result

Once the selected page is closed, MCP may enter a broken state.

Subsequent page-related commands fail with:

Error: The selected page has been closed. Call list_pages to see open pages.

In my case, the remote browser still had other available pages, so the browser connection itself was not lost. The issue appears to be that MCP cannot recover after its selected target disappears.

Expected Result

If the selected page is closed, MCP should recover gracefully by doing one of the following:

  • allow list_pages to work without requiring a valid selected page
  • automatically fall back to another existing page
  • allow new_page to create a fresh page even after the selected page is gone
  • expose a recoverable state instead of locking the whole session

Why This Matters

This blocks real E2E automation for flows where page closure is an expected outcome, including but not limited to:

  • child tab close flows
  • popup close flows
  • success flows that dismiss the current page
  • any scenario where the active target disappears during normal automation

In these cases, page closure is valid application behavior, but it currently breaks the MCP session itself.

Additional Notes

The browser was still reachable from the remote debugging endpoint after the failure, which suggests this is not a browser disconnect issue but a session/context recovery issue inside MCP.

Reproduction

No response

Expectation

No response

MCP configuration

No response

Chrome DevTools MCP version

latest

Chrome version

No response

Coding agent version

No response

Model version

No response

Chat log

No response

Node version

No response

Operating system

None

Extra checklist

  • I want to provide a PR to fix this bug

Activity

  1. added theissue type on May 11, 2026
  2. OrKoN commented on May 11, 2026

    @OrKoN
    Collaborator

    is it the same issue as fixed with #2030?

  3. OrKoN commented on May 11, 2026

    @OrKoN
    Collaborator

    Please specify which chrome-devtools-mcp version you are using.

  4. yuzhanglong commented on May 11, 2026

    @yuzhanglong
    Author

    Please specify which chrome-devtools-mcp version you are using.

    0.25.0

  5. yuzhanglong commented on May 12, 2026

    @yuzhanglong
    Author

    is it the same issue as fixed with #2030?

    @OrKoN I'm not sure.

  6. OrKoN commented on May 12, 2026

    @OrKoN
    Collaborator

    I am not able to reproduce with 0.26.0 which was released today. Please give it a try.

  7. DerKleineLi commented on May 12, 2026

    @DerKleineLi

    Hit this on v0.26.0 with a real OAuth-popup-close flow today; the dispatch-side fix in #2030 doesn't cover the response-build side, so the bug class is still live in that version.

    Reproduction on v0.26.0

    1. Use chrome-devtools-mcp to drive a "Sign in with X" page that uses a Google one-tap popup (e.g. https://x.com/i/flow/login while signed out).
    2. select_page the OAuth account-chooser popup, click the account, popup self-closes on completion (window.close() from Google's flow). This bypasses MCP's structured close path — same as the OP's "page closure as valid application behavior" scenario.
    3. Subsequent mcp__chrome-devtools__list_pages returns Error: The selected page has been closed. Call list_pages to see open pages.

    Why #2030 wasn't sufficient

    #2030 moved getSelectedMcpPage() inside the 'pageScoped' in tool branch of src/index.ts — fixes the dispatch side. But the response-build pipeline still requires a live selected page to enumerate thirdPartyDeveloperTools + webmcpTools. Stack from the live failure points to src/McpResponse.ts:557 and :564:

    let thirdPartyDeveloperTools: ToolGroup<ToolDefinition> | undefined;
    if (this.#listThirdPartyDeveloperTools) {
      const page = this.#page ?? context.getSelectedMcpPage();  // ← throws when selection dead
      thirdPartyDeveloperTools = await getToolGroup(page);
      page.thirdPartyDeveloperTools = thirdPartyDeveloperTools;
    }
    
    let webmcpTools: WebMCPTool[] | undefined;
    if (this.#listWebMcpTools && this.#args.categoryExperimentalWebmcp) {
      const page = this.#page ?? context.getSelectedMcpPage();  // ← same
      webmcpTools = page.getWebMcpTools();
    }

    list_pages and select_page both call response.setListThirdPartyDeveloperTools() + response.setListWebMcpTools(), so the response builder hits these blocks even though the handlers themselves are selection-independent. With the popup-target dead, the build throws and the call surfaces the same "selected page has been closed" error — making recovery via list_pages / select_page impossible, matching the OP's report.

    Suggested fix

    Wrap the two fallback blocks in try/catch so enrichment fails silently when there's no valid selection. list_pages returns the tab list, select_page(pageId) re-selects, and the dev-tools/webmcp listings just don't appear in those particular responses (which is correct — they're not page-scoped operations).

    I have this running locally as a JS patch on the built artifact (reference) and verified the full reproducer above turns green post-patch. Happy to file a PR with the TS-side change against src/McpResponse.ts if helpful — would land cleanly on top of #2030.

    (Closing #2033 was reasonable given the partial fix; flagging this here rather than opening a new issue since the failure mode is identical.)


    Edit 2026-05-12: Retested on pristine v0.26.0 — bug doesn't reproduce with the default registration; my original repro was tainted by a local JS patch I'd applied on first install. Apologies for the confusion.

  8. OrKoN commented on May 12, 2026

    @OrKoN
    Collaborator

    Thanks, that makes sense although listThirdPartyDeveloperTools and listWebMcpTools are disabled by default so unless you have them enabled you should not see an error.

  9. athuljayaram commented on May 12, 2026

    @athuljayaram

    Error: The selected page has been closed. Call list_pages to see open pages.

  10. lueluelue2006 commented on Aug 18, 2026

    @lueluelue2006

    This appears to have regressed in [email protected].

    I can reproduce it reliably with a clean A/B test against 1.6.0 and 1.7.0. The reproducer uses a fresh temporary Chrome profile and a scripted raw MCP stdio client. No coding agent, wrapper/bridge, --autoConnect, or --experimentalPageIdRouting is involved.

    Environment

    • macOS 26.4 (arm64)
    • Chrome 151.0.7922.138
    • Node.js 24.4.1
    • Connection mode: --browserUrl http://127.0.0.1:<port>
    • MCP client: scripted raw MCP stdio client
    • Model: N/A

    Reproduction

    1. Launch Chrome with an isolated temporary profile and an initial about:blank page.

    2. Start Chrome DevTools MCP with:

      npx -y chrome-devtools-mcp@VERSION --browserUrl http://127.0.0.1:<port> --no-usage-statistics --no-performance-crux

    3. Call list_pages.

    4. Call new_page with a data URL so the new page becomes selected.

    5. Close that target externally through Chrome's /json/close/<targetId> endpoint. This simulates the selected target disappearing because of user action, page logic, or host behavior.

    6. Call list_pages again.

    The same reproduction was run against both package versions.

    A/B result

    [email protected] succeeds:

    Note: the previously selected page was closed. Page 1 is now selected.
    ## Pages
    1: about:blank [selected]
    

    [email protected] fails:

    isError=true
    The selected page has been closed. Call list_pages to see open pages.
    

    Relevant 1.7.0 log excerpt:

    list_pages request: {}
    list_pages context: resolved
    list_pages error: Error: The selected page has been closed. Call list_pages to see open pages.
        at McpContext.getSelectedMcpPage (...)
        at ToolHandler.handle (...)
    

    Suspected regression

    In 1.7.0, ToolHandler.handle() collects page context before response.handle():

    devToolsData = await context.getDevToolsData(page);
    const targetPage = page ?? context.getSelectedMcpPage();
    if (targetPage?.pptrPage?.isClosed() === false) {
      pageUrl = targetPage.pptrPage.url();
    }
    
    const {content, structuredContent} = await response.handle(
      context,
      dataFormat,
    );

    For list_pages, page is undefined because the tool is not page-scoped. If the selected page has already closed, context.getSelectedMcpPage() throws before response.handle() gets a chance to refresh the page snapshot and apply the existing closed-page fallback.

    The pre-response page-context lookup appears to have been introduced by commit 6398b7e / PR #2455 (feat(telemetry): report whether tool call is made on localhost). The same lookup is still present on current main as of 2026-08-18. 1.6.0 does not have this lookup at this point in the handler and recovers correctly in the same test.

    Telemetry/context collection here should probably be best-effort so it cannot turn a recoverable non-page-scoped tool call into an error. A regression test exercising the complete ToolHandler path after externally closing the selected page would also catch this; invoking only the list_pages handler would miss the failure because it happens between the handler and response.handle().

    Could this issue be reopened for the 1.7.0 regression?

  11. OrKoN commented on Aug 18, 2026

    @OrKoN
    Collaborator

    @lueluelue2006 can you please file a new issue as it appears to be a new regression? cc @yulunz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions