文件历史

提交图

19 次代码提交

作者 SHA1 备注 提交日期
@masamaru0513 90d368d343 feat: support filePath in evaluate_script (#2054)
## 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

- **Same pattern as existing tools**: Follows the `context.saveFile()`
pattern established by `take_snapshot` (#463), `take_screenshot`,
`get_network_request` (#795), and performance tools (#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>
2026-05-14 08:33:27 +00:00
Wolfgang Beyer e046c23563 chore: in-page tool output: stash DOM elements and preprocess for serialization (#1877)
Improvements for handling in-page tool responses. In order to
successfully pass an in-page tool response from the page context to the
MCP server, the response needs to be serializable. The code walks the
response object an performs the following changes:

- DOM elements are stashed onto the window object and replaced with an
ID. On the MCP server side this ID is used to map back to the
corresponding UID in the page snapshot generated from the accessibility
tree.
- Circular references are replaced with a string.
- Class instances (which can be complex or non-serializable) are
replaced with a string.
- Functions are replaced with a string.

If the in-page tool response contains DOM elements which are not part of
the page snapshot, a new snapshot is created add the missing elements
are added explicitly.
2026-04-22 14:51:09 +00:00
Nicholas Roscino ec895f195a refactor: use puppeteer Extension API (#1911)
This PR refactor the extension usages using the new Puppeteer API.

Requires puppeteer release before merging
2026-04-20 14:38:48 +00:00
Nikolay Vitkov da33cb5b95 feat: auto handle dialogs during script evaluation (#1839)
Provide a argument to LLM to handle dialogs that come up during code
execution.

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2026-04-20 06:42:05 +00:00
Alex Rudenko c2d8009ff7 refactor: move main files (#1120)
- `chrome-devtools-mcp.js` is the `npx chrome-devtools-mcp`
- `chrome-devtools.js` is the new CLI
- `-cli-options.js` is the corresponding options
- all these files are in the bin folder to indicate they are executable
2026-03-05 21:51:37 +00:00
Nicholas Roscino e5973fd021 chore: implement trigger extension action (#1049)
This PR implements the ability to trigger an extension action by passing
it an extension id.
It uses puppeteer internals and the canary chrome version in tests since
the TriggerAction CDP command is still not available in the current
stable release.
2026-03-02 16:21:58 +00:00
Alex Rudenko e51ba47203 fix: simplify emulation and script tools (#1073)
- reduces the token usage.
- makes emulation and script compatible with CLI.
- documents .nullable() and .object() restrictions for the future.
- the emulation tools do not have nullable anymore and undefined would
clear the emulation instead. The model is thus required to provide all
emulation settings at once.

Closes https://github.com/ChromeDevTools/chrome-devtools-mcp/issues/918
2026-03-02 13:31:55 +00:00
Nicholas Roscino 505089c288 chore: evaluate script on service workers (#1052)
This PR introduce script evaluation on service workers behind the flag
--category-extension.
2026-02-27 13:29:17 +00:00
Alex Rudenko 4cb5a17b57 refactor: remove page passing via context (#1061)
- removes several redundant getters on the context.
- removes passing page instances via context.
2026-02-27 12:08:10 +00:00
Alex Rudenko 40c241bbfc refactor: move dialog handling to McpPage (#1059)
- renamed getSelectedPage to getSelectedPptrPage
- removes getSelectedPptrPage from tool interfaces
- moves dialog handling to McpPage
- makes responses to be optionally McpPage-scoped
2026-02-27 11:49:43 +01:00
Alex Rudenko 302e5a0419 refactor: consistently use McpPage in tools (#1057)
Follow-up to
https://github.com/ChromeDevTools/chrome-devtools-mcp/commit/caf601a32832bb87cfac801a6bbeacb87508412f

The work is not complete and as a follow-up I will handle other Context
methods and moved whatever is relevant to the McpPage. Also, duplicate
getters would go away.
2026-02-27 09:41:08 +00:00
Alex Rudenko 5f694c60ff refactor: improve type safety for page scoped tools (#1051)
I think we should create proper classes for tool definitions soon.

Follow-up for
https://github.com/ChromeDevTools/chrome-devtools-mcp/pull/1022
2026-02-26 14:33:57 +00:00
Simon Zünd 8e90a92780 chore: split withBrowser into withBrowser and withMcpContext (#620)
I split this PR off from my "create one DevTools universe per page" PR
in preparation. This allows tests to re-use browser instances without
creating an `McpContext`.

Drive-by: Move mocked browser/page into utils.ts.
2025-11-28 07:52:52 +01:00
zyzyzyryxy 94752ffade fix: prevent dropping license notices on some files when publishing (#604)
This PR prevents license notices being dropped when creating package for
publication.

This can happen when first import in the file is type-only import that
gets removed during build. When there is no empty line between the
license block comment and such import, the comment is treated as related
to the import and gets removed alongside it.
Adding an empty line between copyright notice and the import fixes the
issue.

Co-authored-by: Piotr Paulski <piotrpaulski@chromium.org>
2025-11-24 12:38:30 +00:00
Nikolay Vitkov 4c65f59cf9 fix: retrieve data correctly with fewer than 3 navigations (#451)
Also adds test for navigation
2025-10-21 16:53:30 +00:00
Nikolay Vitkov 053f1f830d fix: allow evaluating in Frames (#443)
Closes https://github.com/ChromeDevTools/chrome-devtools-mcp/issues/439
2025-10-21 10:36:09 +02:00
Nikolay Vitkov 15277541d8 chore: add additional EsLint rule (#147) 2025-09-25 17:20:01 +02:00
Alex Rudenko c663f4d7f9 feat: support script evaluate arguments (#40)
This change allows clients to pass snapshot elements as arguments.
2025-09-16 17:44:53 +02:00
Alex Rudenko 31a0bdce26 feat: initial version 2025-09-11 12:46:05 +02:00