Skip to content

list_console_messages misses messages logged before the server attached #2382

Description

@thomasbachem

Description of the bug

list_console_messages only reports messages emitted after the server attached. Attach to an already-loaded page (e.g. --browserUrl against a browser that's been running a while) and it returns <no console messages found> even though the page logged plenty during load – all sitting right there in a DevTools window.

It's a quiet failure – an empty listing reads as "the page logged nothing", and it cost me a bogus diagnosis before I spotted it.

The messages aren't lost. Chromium buffers them and replays them via Runtime.consoleAPICalled to every new CDP session that calls Runtime.enable. Puppeteer calls Runtime.enable itself during connect(), so the replay is emitted on the page before any consumer can subscribe – page.on('console') never sees it.

PR: #2383.

Reproduction

  1. Start Chrome with --remote-debugging-port, and have a page log something (console.log('PRE-ATTACH'))
  2. Start chrome-devtools-mcp with --browserUrl against it
  3. list_console_messages -> <no console messages found>
  4. Log something new -> only that one shows up

A fresh raw CDP session on the same page replays what step 3 missed, so the buffer is intact. It's also reachable from the server's own page object:

const session = await page.createCDPSession();
session.on('Runtime.consoleAPICalled', ...);
await session.send('Runtime.enable'); // replays the whole buffer

That recovered every buffered message in my test, and page.on('console') kept working afterwards.

Expectation

list_console_messages includes what the page logged before the server attached – or failing that, says the listing only starts at attach, so an empty result isn't mistaken for a clean page.

A backfill would double up on anything the live collector already holds, so it presumably wants dedup, or to run before the collector subscribes. Happy to send a PR if you have a preference on which.

Chrome DevTools MCP version

1.6.0 (on main too)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions