evaluate
Runs JavaScript in a browser tab and returns its value as JSON, letting agents read page globals or compute values in the live page. Use when snapshot or wait tools can't get the data.
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. 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.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| 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. |