Evaluate JavaScript
evaluate_scriptFor actions other tools miss, execute custom JavaScript in the page and get JSON results, with optional element references from snapshots.
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. Errors are returned as a string beginning with "Error:" rather than raised.
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. | |
| function | Yes | 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. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |