Evaluate JavaScript
evaluate_scriptRun custom JavaScript in the page and get a JSON result—use it to read computed styles, call page APIs, or extract structured data in one round trip.
Instructions
Run JavaScript inside the page and get the result back as JSON.
The escape hatch for anything the other tools do not cover: reading computed styles, calling a page's own JS API, or extracting structured data in a single round trip instead of a dozen snapshot-and-click cycles.
Without args the function runs at page level in the main world. With
args, the given uids become real element references, which is how you
operate on one specific element from a snapshot.
Return values must be JSON-serialisable — DOM nodes, functions and circular structures are not, so map them to plain values inside the function. A script that throws comes back as a failed call carrying the JavaScript error, not as a result you have to inspect for the word "Error".
Pass script_path to run a function kept in a .js file, and file_path to write the result to disk instead of into the conversation.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| args | No | Element uids from the most recent take_snapshot, resolved to live DOM nodes and passed as the function's arguments. The first uid is also bound as `this`. Omit for page-level scripts. | |
| frame | No | Run inside one of the page's frames instead of the main document: an index or frame id from list_frames. Runs in an isolated world, which shares the frame's DOM but not its own JavaScript variables, so use it to read and drive the DOM rather than to call the page's own functions. Ignored when `args` is given, since a uid already carries its frame. | |
| browser | No | Which browser to act on. Each name is an independent Chrome, created on first use. Omit for the shared default; parallel agents each need their own name. | default |
| function | No | A JavaScript function expression, e.g. "() => document.title" or "(el) => el.innerText". It is invoked immediately and its return value is JSON-serialised back to you. Async functions are awaited, so "async () => (await fetch('/api/x')).json()" works. Return a value — console.log output is not captured. Leave empty when using script_path. | |
| file_path | No | Write the JSON result to this local path instead of returning it — for extractions too large to put in the conversation. | |
| script_path | No | Read the function from this local .js file instead of the `function` parameter. Use it for anything long or quote-heavy, where escaping the script into a JSON string is where the mistakes happen. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |