feat: add filePath parameter to take_snapshot and evaluate_script#248
Closed
Coquinate wants to merge 2 commits into
Closed
feat: add filePath parameter to take_snapshot and evaluate_script#248Coquinate wants to merge 2 commits into
Coquinate wants to merge 2 commits into
Conversation
Collaborator
|
Hey, Could you please incorporate those in this PR and will review after. |
Contributor
Author
|
Updated to use |
Add optional filePath parameter to save tool output directly to files instead of including in response. Features: - take_snapshot can save accessibility tree to file - evaluate_script can save JSON result to file - Reduces token usage for large outputs - Enables offline analysis and processing - Backwards compatible - tools work as before when filePath is omitted Implementation: - Added filePath optional parameter to both tool schemas - Write formatted output to file using writeFile from node:fs/promises - Updated Context interface to expose createTextSnapshot and getTextSnapshot - Includes comprehensive tests for file saving functionality Resolves ChromeDevTools#153
Updates take_snapshot and evaluate_script to use context.saveFile() instead of direct writeFile() calls, following the pattern established in PR ChromeDevTools#250. Changes: - Removed direct fs/promises imports - Convert string data to Uint8Array using TextEncoder - Use context.saveFile() for consistent file writing - Update response messages to use returned filename 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
f4b451c to
acaabdc
Compare
Collaborator
|
Could you please sign the CLA (see the failing check) https://github.com/ChromeDevTools/chrome-devtools-mcp/pull/248/checks?check_run_id=52444256994? |
Collaborator
|
Closing due to conflicts. It is partially addressed by other PRs and we have tracking issues for remaining feature requests. |
pull Bot
pushed a commit
to Mu-L/chrome-devtools-mcp
that referenced
this pull request
May 14, 2026
## 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 ChromeDevTools#463. PR ChromeDevTools#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 - **Same pattern as existing tools**: Follows the `context.saveFile()` pattern established by `take_snapshot` (ChromeDevTools#463), `take_screenshot`, `get_network_request` (ChromeDevTools#795), and performance tools (ChromeDevTools#686). - **Minimal change surface**: Only `performEvaluation()` gains an optional `options` parameter. No new interfaces or abstractions. - **Backwards compatible**: `filePath` is optional. When omitted, behavior is identical to before. ## 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 --------- Co-authored-by: Alex Rudenko <alexrudenko@chromium.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds optional
filePathparameter totake_snapshotandevaluate_scripttools, enabling direct file output instead of response inclusion.Resolves #153
Features
take_snapshotcan save accessibility tree to fileevaluate_scriptcan save JSON result to fileImplementation
filePathparameter to both tool schemaswriteFilefromnode:fs/promisesContextinterface to exposecreateTextSnapshotandgetTextSnapshottake_screenshottoolTesting
Test Plan