Skip to content

feat: list errors a page raises while a tool runs - #3431

Merged
OrKoN merged 2 commits into
ChromeDevTools:mainfrom
thomasbachem:feat/evaluate-script-errors
Nov 13, 2026
Merged

OrKoN merged 2 commits into
ChromeDevTools:mainfrom
thomasbachem:feat/evaluate-script-errors

Conversation

@thomasbachem

@thomasbachem thomasbachem commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3430

Every tool that runs on a page now lists, in its response, the errors the page throws or logs while the tool runs. That covers the page-scoped tools like click, fill or navigate_page, plus evaluate_script and new_page, but not get_devtools_comments, which runs beside other calls while it waits. Without any errors the response is unchanged.

ToolHandler hands each page-scoped tool's page to the response through the new includeConsoleErrorsFrom(), which notes the page's latest console message, and McpResponse.handle() then lists the first ten errors after it under ## Console errors during this call, as consoleErrors in structuredContent, with a pointer to list_console_messages for the rest. evaluate_script and new_page pick their page themselves, so they make that call too. A tool that lists or shows console messages itself, like list_console_messages or get_console_message, keeps its own output, a page closed during the call lists nothing, and service worker evaluations are unchanged.

The list covers what the error type filter of list_console_messages covers: uncaught exceptions and console.error() calls, but also what the browser logs itself, like a failed resource load or a CSP violation. So new_page and navigate_page now also list the errors of the page they load.

It doesn't see errors in out-of-process iframes, since the collector only listens on the page's own session, and a call that navigates more often than maxNavigationSaved allows loses its earliest errors. An error the page raises between two calls shows up in neither response, only in list_console_messages. Happy to change any of that, the cap of ten included, if you'd rather.

The new tests cover the hand-over in ToolHandler, including its skip for concurrency: 'none', in evaluate_script and in new_page, getLatestConsoleMessageId() and getConsoleDataAfter() on an empty collector and across navigations, and the listing in McpResponse with its cap and each case it leaves out or keeps apart. Two run in a real browser: evaluate_script with an error thrown in a timer, and new_page loading a page that logs one. npm run test passes locally, on the branch and merged onto main (macOS, Node 24).

@OrKoN

OrKoN commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

I wonder if should just do it automatically for any tool call in the tool handler? I.e., if there are new messages during the call we include them in the response?

@OrKoN

OrKoN commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

I think keeping to errors only in reasonable.

@Lightning00Blade

Copy link
Copy Markdown
Collaborator

The idea looks good. I am curious if the API should just be something like "attach messaged during execution" and then all the handling is on the Tool/Response layers so we don't need to handle it on each tool handle. but we do something similar to includePages.

@thomasbachem

Copy link
Copy Markdown
Contributor Author

Thanks, both. I'll move it into ToolHandler for the tools that run on a page and keep the listing in McpResponse. evaluate_script and new_page pick their page themselves, so they'd each hand it over with one call, much like setIncludePages(). Errors only, as you say.

@thomasbachem
thomasbachem force-pushed the feat/evaluate-script-errors branch from e9bd0d8 to 7a9fbc0 Compare November 10, 2026 21:53
@thomasbachem thomasbachem changed the title feat: list errors raised while evaluate_script runs feat: list errors a page raises while a tool runs Nov 10, 2026
@thomasbachem

Copy link
Copy Markdown
Contributor Author

Done, it now runs for every page-scoped tool in ToolHandler, plus evaluate_script and new_page, under its own heading and capped at ten errors. I updated the description to match.

@OrKoN
OrKoN self-requested a review November 11, 2026 06:41

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

Please check the following:

  1. PR description, src/McpResponse.ts includeConsoleErrorsFrom(): Remove the claim "An error the page raises after a call returned lands in the next call's response", or store the last reported id on McpPage. The next call reads its baseline id at its start, so no response lists an error that the page raises between two calls.

  2. tests/McpPage.test.ts: Add mock-based tests for getLatestConsoleMessageId() and getConsoleDataAfter(), including the empty collector and messages from an earlier navigation. AGENTS.md requires a core class test for each new McpPage method, and only real-browser tests call these two methods.

  3. tests/McpResponse.test.ts console errors of a handed over page: Replace the seven withMcpContext tests with tests that use createMockMcpPage() and a stubbed getConsoleDataAfter(). The filter, the cap, and the skip conditions do not need a browser, and tests/tools/script.test.ts already has the end-to-end run.

  4. tests/tools/script.test.ts: Keep one real-browser test for the timer error and move the other three scenarios to mocks or to tests/McpPage.test.ts. AGENTS.md permits at most one slow end-to-end run for each scenario.

  5. tests/ToolHandler.test.ts handOverCases: Replace assert.deepStrictEqual(includeConsoleErrorsFrom.args, ...) with sinon.assert.calledOnceWithExactly() and sinon.assert.notCalled(). AGENTS.md forbids Node assert for stub call verification.

  6. src/McpResponse.ts #handleConsoleErrors(): Pass the DevTools universe of errorsFrom.page to #formatConsoleData(), not this.#page. evaluate_script and new_page do not call setPage(), so this.#page is undefined and ConsoleFormatter.from() gets no devTools for these two tools.

  7. src/McpResponse.ts #formatConsoleData() call in #handleConsoleErrors() (optional): Limit the number of errors before ConsoleFormatter.from() runs, for example with a bounded scan that stops after 10 groups. The collector keeps up to 10,000 messages for each navigation, and the code formats all errors to print 10.

Comment thread src/tools/ToolDefinition.ts Resolved
Keeps getLatestConsoleMessageId() and getConsoleDataAfter() off ContextPage, formats the errors with their page's DevTools universe and moves the tests to mocks.
@thomasbachem

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

  1. Right, the next call starts from its own baseline. I took the sentence out, and the description now says an error raised between two calls only shows up in list_console_messages.
  2. Added, for an empty collector and for messages from an earlier navigation.
  3. Done, they now use createMockMcpPage() with a stubbed getConsoleDataAfter(), plus two for the edges of the cap.
  4. Done. script.test.ts keeps the timer test. The reload and earlier page cases are now McpPage tests, and the script that throws became an McpResponse test of a tool that threw.
  5. Done.
  6. Fixed, with a test. It only affects stack traces, which this section doesn't fetch, so the output doesn't change.
  7. I'd leave this one out if that's ok. Only the call's own errors get formatted, without detailed data or stack traces, so there are no CDP calls, and 10,000 take a few milliseconds here. It groups them all before cutting at ten, like list_console_messages does before paging, which is what keeps the count in N more not shown right.

@OrKoN
OrKoN self-requested a review November 12, 2026 15:33
@OrKoN
OrKoN added this pull request to the merge queue Nov 13, 2026
Merged via the queue into ChromeDevTools:main with commit d5d30bd Nov 13, 2026
15 checks passed
@thomasbachem
thomasbachem deleted the feat/evaluate-script-errors branch November 24, 2026 15:23
mijanurecon452-tech pushed a commit to mijanurecon452-tech/chrome-devtools-mcp that referenced this pull request Nov 24, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.14.0](ChromeDevTools/chrome-devtools-mcp@chrome-devtools-mcp-v1.13.0...chrome-devtools-mcp-v1.14.0)
(2026-11-24)


### 🎉 Features

* add --backgroundNewPages to keep new_page tabs in the background
([ChromeDevTools#3539](ChromeDevTools#3539))
([7a39d6d](ChromeDevTools@7a39d6d))
* add abort and allow-origin network mocks
([ChromeDevTools#3421](ChromeDevTools#3421))
([eb4b53d](ChromeDevTools@eb4b53d))
* add inspect-in-devtools skill and claude plugin command
([ChromeDevTools#2696](ChromeDevTools#2696))
([aa977a6](ChromeDevTools@aa977a6))
* add network requests from service workers
([ChromeDevTools#3554](ChromeDevTools#3554))
([11162da](ChromeDevTools@11162da))
* add service workers to get_console_message
([ChromeDevTools#3537](ChromeDevTools#3537))
([2e247a4](ChromeDevTools@2e247a4))
* include computed styles in get_css_styles
([ChromeDevTools#3538](ChromeDevTools#3538))
([cf98d8b](ChromeDevTools@cf98d8b))
* list errors a page raises while a tool runs
([ChromeDevTools#3431](ChromeDevTools#3431))
([d5d30bd](ChromeDevTools@d5d30bd))
* resolve CSS custom variable values inline in `get_css_styles`
([ChromeDevTools#3481](ChromeDevTools#3481))
([8ba2ac9](ChromeDevTools@8ba2ac9))
* support transparent screenshots
([ChromeDevTools#3457](ChromeDevTools#3457))
([045fb8c](ChromeDevTools@045fb8c))
* **telemetry:** send startup events directly from the server process
([ChromeDevTools#3511](ChromeDevTools#3511))
([b14eb81](ChromeDevTools@b14eb81))


### 🛠️ Fixes

* accept POSIX root URIs from WSL2 clients on a Windows server
([ChromeDevTools#3380](ChromeDevTools#3380))
([4b9acc9](ChromeDevTools@4b9acc9))
* align root plugin.json name with marketplace entry
([ChromeDevTools#3474](ChromeDevTools#3474))
([1424980](ChromeDevTools@1424980))
* **cli:** enable off by default categories in CLI except PWA
([ChromeDevTools#3595](ChromeDevTools#3595))
([0ff265d](ChromeDevTools@0ff265d))
* **cli:** handle array of strings correctly
([ChromeDevTools#3593](ChromeDevTools#3593))
([d197b28](ChromeDevTools@d197b28))
* **cli:** match yargs-parser when detecting negative numbers
([ChromeDevTools#3548](ChromeDevTools#3548))
([eb9b030](ChromeDevTools@eb9b030))
* **cli:** pass option values starting with `-` through to tools
([ChromeDevTools#3501](ChromeDevTools#3501))
([ec0abfc](ChromeDevTools@ec0abfc))
* **cli:** preserve daemon PID when SIGKILL fails
([ChromeDevTools#3485](ChromeDevTools#3485))
([0788697](ChromeDevTools@0788697))
* **cli:** reuse live daemons after EPERM
([ChromeDevTools#3452](ChromeDevTools#3452))
([1417f93](ChromeDevTools@1417f93))
* **cli:** strip terminal escape sequences from tool output and errors
([ChromeDevTools#3536](ChromeDevTools#3536))
([ec2fb15](ChromeDevTools@ec2fb15))
* **config:** reject --browserUrl values without an http(s) scheme
([ChromeDevTools#3437](ChromeDevTools#3437))
([e40cef6](ChromeDevTools@e40cef6))
* **config:** reject --viewport values with more than two parts
([ChromeDevTools#3577](ChromeDevTools#3577))
([ab911a6](ChromeDevTools@ab911a6))
* **console:** keep stack traces of messages from earlier navigations
([ChromeDevTools#3397](ChromeDevTools#3397))
([e8798d6](ChromeDevTools@e8798d6))
* **console:** resolve Error arguments on the session of their handle
([ChromeDevTools#3408](ChromeDevTools#3408))
([4c6c767](ChromeDevTools@4c6c767))
* dedicated worker can now build a stack trace
([ChromeDevTools#3572](ChromeDevTools#3572))
([9762165](ChromeDevTools@9762165)),
closes
[ChromeDevTools#2962](ChromeDevTools#2962)
* do not queue unknown page ids
([ChromeDevTools#3599](ChromeDevTools#3599))
([4dc8cbc](ChromeDevTools@4dc8cbc))
* **emulation:** reject non-string extraHttpHeaders values
([ChromeDevTools#3484](ChromeDevTools#3484))
([64d4726](ChromeDevTools@64d4726))
* explain DevToolsActivePort permission errors during autoConnect
([ChromeDevTools#3487](ChromeDevTools#3487))
([0e49c59](ChromeDevTools@0e49c59))
* **extensions:** preserve list_extensions fields in JSON output
([ChromeDevTools#3592](ChromeDevTools#3592))
([02b146b](ChromeDevTools@02b146b))
* **input:** allow multi-file upload_file through chooser-opening
elements
([ChromeDevTools#3436](ChromeDevTools#3436))
([ef680a3](ChromeDevTools@ef680a3))
* **input:** return when click_at, type_text, drag or press_key opens a
dialog
([ChromeDevTools#3576](ChromeDevTools#3576))
([7bcb86d](ChromeDevTools@7bcb86d))
* keep temp files under the temp dir
([ChromeDevTools#3372](ChromeDevTools#3372))
([d666acf](ChromeDevTools@d666acf))
* remove commands from claude plugin
([ChromeDevTools#3469](ChromeDevTools#3469))
([e2f08b4](ChromeDevTools@e2f08b4))
* respect tool timeouts in CLI daemon responses
([ChromeDevTools#3443](ChromeDevTools#3443))
([86a1c23](ChromeDevTools@86a1c23))
* **snapshot:** keep extra element UIDs reusable
([ChromeDevTools#3493](ChromeDevTools#3493))
([4559cd5](ChromeDevTools@4559cd5))
* treat local host name and interface addresses as local browser
endpoints
([ChromeDevTools#3463](ChromeDevTools#3463))
([cf587b4](ChromeDevTools@cf587b4))
* use exception events instead of Runtime.exceptionThrown
([ChromeDevTools#3553](ChromeDevTools#3553))
([437f394](ChromeDevTools@437f394))
* validate heap snapshot className regex
([ChromeDevTools#3030](ChromeDevTools#3030))
([343e6b1](ChromeDevTools@343e6b1))
* validate install_pwa and launch_pwa URLs against navigation policy
([ChromeDevTools#3464](ChromeDevTools#3464))
([057a6aa](ChromeDevTools@057a6aa))
* wait for parsed scripts before reporting an unknown logpoint URL
([ChromeDevTools#3461](ChromeDevTools#3461))
([404f331](ChromeDevTools@404f331))


### 📄 Documentation

* clarify that Chrome may clamp resize_page dimensions
([ChromeDevTools#3583](ChromeDevTools#3583))
([b5a41e0](ChromeDevTools@b5a41e0)),
closes
[ChromeDevTools#2998](ChromeDevTools#2998)
* explain the light and browser third-party bundles in AGENTS.md
([ChromeDevTools#3529](ChromeDevTools#3529))
([835c09a](ChromeDevTools@835c09a))
* fix typos in comments, tests and skill docs
([ChromeDevTools#3489](ChromeDevTools#3489))
([f312b72](ChromeDevTools@f312b72))


### ⚡ Performance

* **telemetry:** start the watchdog process on the first event that
needs it
([ChromeDevTools#3513](ChromeDevTools#3513))
([a4c550d](ChromeDevTools@a4c550d))


### 🏗️ Refactor

* **build:** split Puppeteer and DevTools into a separate bundle
([ChromeDevTools#3510](ChromeDevTools#3510))
([1067857](ChromeDevTools@1067857))
* **config:** import ConfigWatcher without the browser bundle
([ChromeDevTools#3520](ChromeDevTools#3520))
([24dba69](ChromeDevTools@24dba69))
* create BrowserManager without the browser bundle
([ChromeDevTools#3563](ChromeDevTools#3563))
([e8763f9](ChromeDevTools@e8763f9))
* **formatters:** rename MAX_NAME_LENGTH to
HEAP_SNAPSHOT_MAX_NAME_LENGTH
([ChromeDevTools#3591](ChromeDevTools#3591))
([92250bc](ChromeDevTools@92250bc))
* load DevTools in HeapSnapshotManager on first use
([ChromeDevTools#3564](ChromeDevTools#3564))
([d8035c6](ChromeDevTools@d8035c6))
* load McpResponse when ToolHandler builds a response
([ChromeDevTools#3565](ChromeDevTools#3565))
([e4669b3](ChromeDevTools@e4669b3))
* **telemetry:** extract sending to Clearcut into sendToClearcut()
([ChromeDevTools#3509](ChromeDevTools#3509))
([7354c59](ChromeDevTools@7354c59))
* **telemetry:** generate the session id in ClearcutLogger
([ChromeDevTools#3516](ChromeDevTools#3516))
([ea19ce7](ChromeDevTools@ea19ce7))
* **telemetry:** import flagUtils without the browser bundle
([ChromeDevTools#3518](ChromeDevTools#3518))
([ab046de](ChromeDevTools@ab046de))
* **third_party:** re-export Mutex from the light bundle
([ChromeDevTools#3566](ChromeDevTools#3566))
([48466c4](ChromeDevTools@48466c4))
* **tools:** import emulation without the browser bundle
([ChromeDevTools#3521](ChromeDevTools#3521))
([c5d5d7f](ChromeDevTools@c5d5d7f))
* **tools:** import input without the browser bundle
([ChromeDevTools#3522](ChromeDevTools#3522))
([bdecb63](ChromeDevTools@bdecb63))
* **tools:** import logpoints without the browser bundle
([ChromeDevTools#3525](ChromeDevTools#3525))
([71098b0](ChromeDevTools@71098b0))
* **tools:** import memory without the browser bundle
([ChromeDevTools#3526](ChromeDevTools#3526))
([ebb27f9](ChromeDevTools@ebb27f9))
* **tools:** import performance without the browser bundle
([ChromeDevTools#3524](ChromeDevTools#3524))
([ba76587](ChromeDevTools@ba76587))
* **tools:** import snapshot without the browser bundle
([ChromeDevTools#3523](ChromeDevTools#3523))
([110d7f3](ChromeDevTools@110d7f3))
* **utils:** import text utilities without the browser bundle
([ChromeDevTools#3519](ChromeDevTools#3519))
([8029df8](ChromeDevTools@8029df8))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
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.

evaluate_script doesn't report errors thrown by callbacks it schedules

3 participants