evaluate_script
Evaluate JavaScript inside the target page. The source can be provided inline or loaded from a local file. Returns the response as JSON, so returned values have to be JSON-serializable.
Instructions
Evaluate JavaScript inside the target page. The source can be provided inline or loaded from a local file. Returns the response as JSON, so returned values have to be JSON-serializable.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| args | No | An optional list of arguments (element uids from the page content snapshot) to pass to the function. | |
| format | No | How to interpret the source. "function" treats it as a function declaration and supports args. "script" evaluates it as classic JavaScript and does not support args. Defaults to "function". ECMAScript modules are not supported. | |
| pageId | Yes | Targets a specific page by ID. | |
| filePath | No | The absolute or relative path to a file to save the script output to. If omitted, the output is returned inline. | |
| function | No | JavaScript source to execute in the target page. Provide either this or sourcePath, but not both. The source is interpreted according to format. Example without arguments: `() => document.title` or `async () => await fetch("example.com")`. Example with arguments: `(el) => el.innerText` | |
| sourcePath | No | The absolute or relative path to a JavaScript file on the MCP server's local filesystem. Provide either this or function, but not both. | |
| dialogAction | No | Handle dialogs while execution. "accept", "dismiss", or string for response of window.prompt. Defaults to accept. | |
| waitForStableDom | No | Whether to wait for the DOM to settle. Pass false if the script only reads data. Defaults to true. |