Skip to content

feat: add optional stack traces to list_console_messages - #2505

Merged
OrKoN merged 1 commit into
ChromeDevTools:mainfrom
ZayanKhan-12:feat/383-console-stack
Aug 10, 2026
Merged

feat: add optional stack traces to list_console_messages#2505
OrKoN merged 1 commit into
ChromeDevTools:mainfrom
ZayanKhan-12:feat/383-console-stack

Conversation

@ZayanKhan-12

Copy link
Copy Markdown
Contributor

What

Adds an opt-in includeStackTraces parameter to list_console_messages. When set, each listed message includes its resolved (source-mapped, ignore-list-filtered) stack trace — in the text output as indented frames under the message line, and in structuredContent as a pre-formatted stackTrace string, matching the format get_console_message already uses.

Why

Fixes the workflow described in #383: today the list output only contains plain message text, so an LLM debugging a page has to call get_console_message once per message to learn which file/function/line failed. With includeStackTraces: true the model can map every error to its source in a single call.

Design notes:

  • Opt-in, default off — the default output is byte-for-byte unchanged, keeping the token cost of the common path identical.
  • Reuses the existing DevTools stack resolution (createStackTraceForConsoleMessage / SymbolizedError) and the existing formatStackTrace formatting, so frames are source-mapped and ignore-listed exactly like in get_console_message.
  • The per-message "1-based indexing" note is emitted once for the whole list instead of once per message to keep the output compact.
  • Works for console API messages, uncaught errors (including Caused by: chains), and grouped repeated messages ([N times]).

Before / after

Default (unchanged):

## Console messages
Showing 1-1 of 1 (Page 1 of 1).
msgid=1 [log] Hello stack trace! (0 args)

With includeStackTraces: true:

## Console messages
Showing 1-1 of 1 (Page 1 of 1).
msgid=1 [log] Hello stack trace! (0 args)
  at foo (foo.ts:10:2)
  at bar (foo.ts:20:2)
  --- setTimeout -------------------------
  at schedule (util.ts:5:2)
Note: stack trace line and column numbers use 1-based indexing

structuredContent.consoleMessages[i] gains an optional "stackTrace": "at foo (foo.ts:10:2)\nat bar (foo.ts:20:2)\n..." field.

Relationship to #2060

Complements #2060 (source location for list_console_messages, issue #903): that PR surfaces the top-frame location for every message by default, while this one exposes the full stack trace behind an explicit opt-in. The features are independent and the changes are designed to coexist with minimal conflict.

Testing

  • npm run build — passes
  • npm run test:no-build — full suite passes (exit 0)
  • npm run check-format — passes
  • npm run gen — regenerated docs/tool-reference.md, CLI options, and tool-call metrics (included)

New coverage:

  • tests/formatters/ConsoleFormatter.test.ts — snapshot tests for concise toString/toJSON with fetchStackTrace set (console message + uncaught error) and for the unchanged default.
  • tests/tools/console.test.ts — integration tests asserting frames (at failingFn) appear in text and structuredContent when includeStackTraces: true, and are absent by default.

Fixes #383

🤖 Generated with Claude Code

@google-cla

google-cla Bot commented Aug 8, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Adds an opt-in includeStackTraces parameter to list_console_messages.
When set, each listed message includes its resolved, source-mapped
stack trace as indented frames in the text output and as a
pre-formatted stackTrace string in structuredContent, matching the
format used by get_console_message. Default output is unchanged.

Fixes ChromeDevTools#383
@ZayanKhan-12
ZayanKhan-12 force-pushed the feat/383-console-stack branch from 44cdd02 to 3226a6d Compare August 8, 2026 21:46

@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.

LGTM (this matches what we should in DevTools UI so generally could be useful to agents if there are not so many console messages).

@OrKoN
OrKoN enabled auto-merge August 10, 2026 08:51
@OrKoN
OrKoN added this pull request to the merge queue Aug 10, 2026
Merged via the queue into ChromeDevTools:main with commit 85c73a0 Aug 10, 2026
19 checks passed
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.

Expose error stack traces in list_console_messages (feasibility question)

3 participants