Skip to content

feat: support filePath in evaluate_script#2054

Merged
OrKoN merged 4 commits into
ChromeDevTools:mainfrom
masamaru0513:feat/evaluate-script-file-path
May 14, 2026
Merged

feat: support filePath in evaluate_script#2054
OrKoN merged 4 commits into
ChromeDevTools:mainfrom
masamaru0513:feat/evaluate-script-file-path

Conversation

@masamaru0513

@masamaru0513 masamaru0513 commented May 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an optional filePath parameter to evaluate_script that saves the script output to a file instead of returning it inline.

Refs #153

Motivation

Issue #153 requested filePath support for take_snapshot and evaluate_script. take_snapshot was addressed in #463. PR #248 previously attempted this but was closed due to conflicts. This PR implements the same feature on the current codebase, completing the remaining piece.

Changes

  • Add optional filePath parameter to the evaluate_script schema
  • Add context.validatePath(filePath) call for path validation
  • Pass {filePath, context} options to performEvaluation()
  • In performEvaluation(): when filePath is provided, save output via context.saveFile() with .json extension; otherwise return inline as before
  • Update docs/tool-reference.md via npm run docs:generate
  • Add unit test for file output

Key design decisions

Testing

Unit test added (tests/tools/script.test.ts):

  • Call evaluate_script with filePath set to a temp file
  • Assert response contains "Output saved to"
  • Assert file content matches the JSON-serialized return value
  • Clean up temp file in finally block

Manual testing performed:

  • () => document.title with filePath: /tmp/test.json → file contains "Example Domain"
  • () => document.title without filePath → inline ```json block returned (no regression)
  • () => Array.from({length: 100}, ...) with filePath → 100-item array saved correctly
  • filePath pointing to non-existent directory → directory auto-created, file saved
  • Relative path (test.json) → resolved to CWD, absolute path shown in response
  • Function that throws → error returned, no partial file created
  • Existing file as filePath → file overwritten completely

Adds an optional filePath parameter to evaluate_script that saves the
script output to a file instead of returning it inline. This reduces
token usage for large outputs and enables offline analysis.

Follows the same context.saveFile() pattern used by take_snapshot,
take_screenshot, and performance tools.

Refs ChromeDevTools#153
Comment thread src/tools/script.ts Outdated
context is always provided when filePath is set, so it should not be
optional.
@OrKoN OrKoN enabled auto-merge May 14, 2026 05:46
@OrKoN

OrKoN commented May 14, 2026

Copy link
Copy Markdown
Collaborator

LGTM thanks!

@masamaru0513

Copy link
Copy Markdown
Contributor Author

Thank you for the review!

@OrKoN OrKoN added this pull request to the merge queue May 14, 2026
Merged via the queue into ChromeDevTools:main with commit 90d368d May 14, 2026
28 of 30 checks passed
pull Bot pushed a commit to Spencerx/chrome-devtools-mcp that referenced this pull request May 18, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.0.0](ChromeDevTools/chrome-devtools-mcp@chrome-devtools-mcp-v0.26.0...chrome-devtools-mcp-v1.0.0)
(2026-05-18)


### 🎉 Features

* report new URL after actions that trigger navigation
([ChromeDevTools#1853](ChromeDevTools#1853))
([b594858](ChromeDevTools@b594858))
* support filePath in evaluate_script
([ChromeDevTools#2054](ChromeDevTools#2054))
([90d368d](ChromeDevTools@90d368d))


### 🛠️ Fixes

* disable NetworkManager in DevTools
([ChromeDevTools#1834](ChromeDevTools#1834))
([d0e6539](ChromeDevTools@d0e6539))
* do not use getSelectedMcpPage
([85f935b](ChromeDevTools@85f935b))
* improve geolocation emulation
([ChromeDevTools#2036](ChromeDevTools#2036))
([213720b](ChromeDevTools@213720b))
* report unknown tool arguments
([ChromeDevTools#2064](ChromeDevTools#2064))
([041b208](ChromeDevTools@041b208))
* respect user's npm registry configuration in update check
([ChromeDevTools#2038](ChromeDevTools#2038))
([83a299f](ChromeDevTools@83a299f))


### 📄 Documentation

* explain concurrent session options
([ChromeDevTools#2062](ChromeDevTools#2062))
([41944b3](ChromeDevTools@41944b3))
* fix typo
([ChromeDevTools#2075](ChromeDevTools#2075))
([1deb4f8](ChromeDevTools@1deb4f8))
* remove windows workaround and document Node LTS support
([ChromeDevTools#2074](ChromeDevTools#2074))
([30dcd0b](ChromeDevTools@30dcd0b))
* unhide various experimental flags
([ChromeDevTools#2055](ChromeDevTools#2055))
([081c903](ChromeDevTools@081c903))


### 🏗️ Refactor

* waitForResult helpers
([ChromeDevTools#2041](ChromeDevTools#2041))
([f6a12be](ChromeDevTools@f6a12be))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
OrKoN pushed a commit that referenced this pull request May 19, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.0.0](chrome-devtools-mcp-v0.26.0...chrome-devtools-mcp-v1.0.0)
(2026-05-18)


### 🎉 Features

* report new URL after actions that trigger navigation
([#1853](#1853))
([b594858](b594858))
* support filePath in evaluate_script
([#2054](#2054))
([90d368d](90d368d))


### 🛠️ Fixes

* disable NetworkManager in DevTools
([#1834](#1834))
([d0e6539](d0e6539))
* do not use getSelectedMcpPage
([85f935b](85f935b))
* improve geolocation emulation
([#2036](#2036))
([213720b](213720b))
* report unknown tool arguments
([#2064](#2064))
([041b208](041b208))
* respect user's npm registry configuration in update check
([#2038](#2038))
([83a299f](83a299f))


### 📄 Documentation

* explain concurrent session options
([#2062](#2062))
([41944b3](41944b3))
* fix typo
([#2075](#2075))
([1deb4f8](1deb4f8))
* remove windows workaround and document Node LTS support
([#2074](#2074))
([30dcd0b](30dcd0b))
* unhide various experimental flags
([#2055](#2055))
([081c903](081c903))


### 🏗️ Refactor

* waitForResult helpers
([#2041](#2041))
([f6a12be](f6a12be))

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

2 participants