Skip to content

feat: group identical consecutive console messages in list_console_messages - #1939

Merged
OrKoN merged 1 commit into
ChromeDevTools:mainfrom
masamaru0513:feat/group-identical-console-messages
Apr 23, 2026
Merged

OrKoN merged 1 commit into
ChromeDevTools:mainfrom
masamaru0513:feat/group-identical-console-messages

Conversation

@masamaru0513

@masamaru0513 masamaru0513 commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Group consecutive identical console messages in list_console_messages, similar to Chrome DevTools' console grouping behavior.

Fixes #904

Changes

  • Introduce GroupedConsoleFormatter subclass that extends ConsoleFormatter and overrides toString() / toJSON() for count-aware formatting
  • Add ConsoleFormatter.groupConsecutive() static method that groups consecutive messages with the same type, text, and argument count
  • Apply grouping before pagination so grouped counts are accurate and page sizes reflect the collapsed view
  • Add unit tests for grouping logic, string formatting, and JSON output

Key design decisions

Output example

msgid=1 [log] hello world (1 args) [5 times]

Testing

  • Unit tests in tests/formatters/ConsoleFormatterGrouping.test.ts
  • Manual verification: identical messages (×5), mixed pattern (A,A,B,A,A → A×2, B×1, A×2)

@masamaru0513
masamaru0513 force-pushed the feat/group-identical-console-messages branch 2 times, most recently from 46d187b to 65c63d8 Compare April 22, 2026 13:40
Comment thread src/formatters/ConsoleFormatter.ts Resolved
@masamaru0513
masamaru0513 force-pushed the feat/group-identical-console-messages branch from 65c63d8 to 6e3d0de Compare April 22, 2026 14:00
@masamaru0513

masamaru0513 commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@OrKoN
Refactored as suggested, here's a summary of the changes:

  • Introduced GroupedConsoleFormatter subclass that overrides toString() / toJSON()
  • Dropped lastId; only the first message's ID is used
  • No new methods added to the formatter interface
  • ConsoleFormatter and GroupedConsoleFormatter are interchangeable via the same interface

Ready for another look when you get a chance. Thanks!

@OrKoN

OrKoN commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

Please update the PR description accordingly.

@OrKoN
OrKoN self-requested a review April 22, 2026 14:07
@masamaru0513

masamaru0513 commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@OrKoN
Updated the PR description. Sorry about that.

…ssages

Group consecutive console messages with the same type, text, and argument
count into a single entry with a count indicator (e.g. [5 times]).

Introduces GroupedConsoleFormatter subclass that extends ConsoleFormatter
to handle grouped message display.
@OrKoN
OrKoN force-pushed the feat/group-identical-console-messages branch from 6e3d0de to 4c95f28 Compare April 23, 2026 09:42

@OrKoN OrKoN left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@OrKoN
OrKoN added this pull request to the merge queue Apr 23, 2026
Merged via the queue into ChromeDevTools:main with commit dbddb2e Apr 23, 2026
17 checks passed
pull Bot pushed a commit to Mu-L/chrome-devtools-mcp that referenced this pull request May 4, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.24.0](ChromeDevTools/chrome-devtools-mcp@chrome-devtools-mcp-v0.23.0...chrome-devtools-mcp-v0.24.0)
(2026-05-02)


### 🎉 Features

* agentic browsing in lighthouse
([ChromeDevTools#1931](ChromeDevTools#1931))
([5fa2750](ChromeDevTools@5fa2750))
* **cli:** generate commands for conditional tools
([ChromeDevTools#1962](ChromeDevTools#1962))
([b2b3e99](ChromeDevTools@b2b3e99))
* group identical consecutive console messages in list_console_messages
([ChromeDevTools#1939](ChromeDevTools#1939))
([dbddb2e](ChromeDevTools@dbddb2e))
* support MCP client roots feature
([ChromeDevTools#1945](ChromeDevTools#1945))
([def53dd](ChromeDevTools@def53dd))


### 🛠️ Fixes

* add proactive tool rejection when dialog is open
([ChromeDevTools#1978](ChromeDevTools#1978))
([6ce254e](ChromeDevTools@6ce254e))
* always allow tmpdir access with client roots
([ChromeDevTools#1984](ChromeDevTools#1984))
([a90378a](ChromeDevTools@a90378a))
* **cli:** re-generate cli correctly
([ChromeDevTools#1969](ChromeDevTools#1969))
([8cbdb8d](ChromeDevTools@8cbdb8d))
* handle errors due to open dialogs during tool calls
([ChromeDevTools#1953](ChromeDevTools#1953))
([06b331f](ChromeDevTools@06b331f))
* note about missing elements should not show in verbose mode
([ChromeDevTools#1950](ChromeDevTools#1950))
([80bee1e](ChromeDevTools@80bee1e))
* **telemetry:** bucketize string length
([ChromeDevTools#1972](ChromeDevTools#1972))
([bf3cb58](ChromeDevTools@bf3cb58))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
zjdCander pushed a commit to zjdCander/chrome-devtools-mcp that referenced this pull request Nov 26, 2026
…jects (ChromeDevTools#3642)

## Summary

`list_console_messages` merges consecutive messages that log different
objects into one line. `groupConsecutive()` compares type, text and
argument count, and the text comes from Puppeteer's `msg.text()`, which
renders every object argument as a fixed placeholder like `[object
Object]`. So a loop such as `items.forEach(i => console.log(i))` shows
up as a single entry, and only the first message ID is listed. The other
objects can only be reached by guessing their IDs for
`get_console_message`.

ChromeDevTools#1939 kept only the first ID on the assumption that grouped messages are
identical. That doesn't hold for object arguments. A number and a string
with the same text (`console.log(1)` then `console.log('1')`) were also
merged.

## Reproduction

A page that runs:

```js
for (const user of [{id: 1}, {id: 2}, {id: 3}]) console.log(user);
console.log(1);
console.log('1');
for (const id of [10, 20]) console.error({failedId: id});
```

`list_console_messages` on main:

```
msgid=1 [log] [object Object] (1 args) [3 times]
msgid=4 [log] 1 (1 args) [2 times]
msgid=6 [error] [object Object] (1 args) [2 times]
```

`get_console_message msgid=2` returns the second object, but msgid=2
never appears in the list.

With this change all 7 messages are listed separately.

## Fix

`groupConsecutive()` now also compares the arguments' remote objects
(type, subtype, value, unserializableValue, description), the same
fields DevTools compares in `ConsoleMessage.isEqual`. As in DevTools, an
argument that is an object other than an error never compares equal.
Null is treated as a plain value and still groups. Uncaught errors have
no arguments, so they still group by their text as before.

## User-visible changes

Both places that use `groupConsecutive()` change the same way:
`list_console_messages` and the "Console errors during this call"
section that `navigate_page`, `evaluate_script` and other tools append.

- Consecutive messages that log a non-error object (plain objects,
arrays, DOM nodes, Map/Set) are listed one per message instead of as `[N
times]`. A loop that logs objects now produces N lines, so output grows
in that case. Because there are fewer groups, the 10-entry cap on
"Console errors during this call" can fill sooner.
- Primitives with the same text but a different type are no longer
grouped.
- Messages that log errors with the same message but a different stack
are no longer grouped.
- Repeated identical strings, numbers, null, identical errors, and
repeated uncaught errors or promise rejections still group as before.

## Tests

Seven new cases in `tests/formatters/ConsoleFormatterGrouping.test.ts`.
Three fail on main (different objects, number vs string, errors with
different stacks) and pass with the fix. The others check that same
strings, null, same errors and repeated uncaught errors still group.

`npm run check-format` and `npm run build` are clean. `npm run test`
passes locally (macOS arm64, Node 24, Chrome for Testing 157). I also
ran the built server against the page above and against pages logging
repeated strings, repeated uncaught errors from `setInterval`, and
repeated identical promise rejections: those still group.

Same call site is still not part of the comparison (DevTools also
compares url, line and stack), so identical text logged from different
lines still groups, same as main. That seemed like a separate change.
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.

Identical console messages should be grouped together in the list_console_messages tool

2 participants