execute_js
Run JavaScript in the page to inspect or modify DOM, trigger hover-dependent states, and wait for async UI updates when CSS selectors and standard interactions lack the needed control.
Instructions
Execute arbitrary JavaScript in the page context and return the evaluation result. The script runs in the browser's main frame with full access to the DOM, window, and page APIs. Use as a last resort when CSS selectors and other tools cannot achieve the interaction — prefer click, fill_form, and select_option for standard interactions. Optionally accepts hover_selector to hover over an element before executing the script, enabling inspection of CSS :hover styles and hover-triggered DOM changes. When the script triggers reactive DOM changes (e.g., .click() on a toggle), the return value may reflect pre-mutation state because frameworks schedule updates asynchronously. Set settle_ms (e.g., 50) to wait for reactivity to flush before capturing the result.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| script | Yes | JavaScript code to execute in the page context, serialized to JSON on return. Accepts an expression ("document.title"), a statement list whose final expression is the result ("const t = document.title; t.length"), or a body that returns explicitly ("return document.title"). Top-level 'await' is supported ("await fetch('/api/data').then(r => r.json())"). | |
| settle_ms | No | Milliseconds to wait after script execution before capturing the return value (max 5000). Use when the script triggers DOM mutations that a reactive framework (Vue, React, etc.) processes asynchronously — a value of 50-100ms allows framework reactivity to flush before reading state. Default: 0 (no delay). | |
| hover_selector | No | Optional CSS selector or @eN ref (from page_map) of an element to hover over BEFORE executing the script. When provided, the mouse is moved over the element (triggering :hover CSS pseudo-class), then the script is evaluated. This allows inspecting hover-dependent computed styles (e.g. getComputedStyle(el).color after hover) or verifying hover-triggered DOM changes. |