Skip to content

list_console_messages history is wiped by same-document (SPA) navigations #2650

Description

@baishiwen9

Description of the bug

list_console_messages only returns messages logged after the most recent same-document navigation. When a page uses the History API (history.pushState / replaceState) or changes the hash to switch routes (typical single-page apps), the collected console history is silently reset even though the page never actually reloaded. This makes the tool unreliable for debugging SPA console output, and it is inconsistent with list_network_requests, which correctly keeps data across SPA route changes.

Reproduction

  1. Serve a page that logs to the console at load:
<!DOCTYPE html>
<html>
  <head><meta charset="utf-8"><title>test</title></head>
  <body>
    <script>
      console.log('BEFORE_NAV_MSG_1');
      console.log('BEFORE_NAV_MSG_2');
    </script>
  </body>
</html>
  1. Start the server: npx chrome-devtools-mcp@latest --headless
  2. Call new_page with the URL above.
  3. Call list_console_messages → returns BEFORE_NAV_MSG_1 and BEFORE_NAV_MSG_2.
  4. Call evaluate_script to perform a same-document navigation and log again:
() => { history.pushState({}, '', '/route2'); console.log('AFTER_NAV_MSG'); return location.pathname; }

The tool response even reports Page navigated to http://localhost:8765/route2. even though the page did not reload.

  1. Call list_console_messages again → only AFTER_NAV_MSG is returned; the two pre-navigation messages are gone.

Expectation

Expected behavior

A same-document navigation (no actual page reload) should not clear the console history. list_console_messages should keep returning the earlier messages, consistent with list_network_requests, which retains data across SPA route changes.

Actual behavior

The two pre-navigation messages disappear after history.pushState; only messages logged after the route change remain.

MCP configuration

No response

Chrome DevTools MCP version

1.8.0

Chrome version

152

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 Sep 3, 2026
  2. OrKoN commented on Sep 3, 2026

    @OrKoN
    Collaborator

    I think it might a good idea to exclude same-document navigations from the collectors so that data for the last 3 cross-document navigations is persisted (currently it is persisted for 3 navigations of any kind). Reporter, you can use includePreservedMessages: true on the list_console_messages to get all preserved messages across last 3 navigations.

  3. changed the issue type fromtoon Sep 3, 2026
  4. lisa0314 commented on Sep 4, 2026

    @lisa0314
    Contributor

    I would like to work on this. I will follow the suggested direction and make collector history rotate only for cross-document navigations, while keeping same-document History API and hash navigations in the current bucket. I will add focused coverage for same-document navigation and verify that real navigations and reloads still rotate the retained history.

  5. added a commit that references this issue on Sep 10, 2026
    aa25562
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions