evaluate
Execute JavaScript in a browser tab or frame and return the JSON-serializable result. Promises are awaited, and thrown errors return their exception messages.
Instructions
Run JavaScript in a tab and return its value as JSON in { result }. A bare expression returns its value; for several statements use return ...; promises are awaited. Values that aren't JSON come back reduced: undefined as null and DOM nodes as {}. It runs in the page's main world (can read page globals like window.dataLayer); on stealth sessions (see set_stealth) it runs in an isolated world instead, which sees the DOM but not page-defined globals. tabIndex runs it in another tab without switching to it, and frame in an embedded frame. The code can change the page like any script, so prefer take_snapshot or wait_for when they suffice, and click or type for interaction. Fails with the JS exception's message if the code throws.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"sessionId": "<sessionId>",
"expression": "<expression>"
},
"name": "evaluate"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| frame | No | Run in the frame whose URL contains this (an embedded form from another site, e.g. `greenhouse.io`), in an isolated world that sees its DOM but not its page globals. Default: the top document. | |
| tabIndex | No | Tab to run in, by its 0-based list_pages index. Default: the active tab. | |
| sessionId | Yes | The id returned by open_browser_session. Errors if no open session has it. | |
| expression | Yes | JavaScript to run. Promises are awaited; the value must be JSON-serializable. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes | The expression's value; null for undefined. |