browser_evaluate
Execute JavaScript in the browser to interact with hidden or shadow DOM elements. Run arbitrary code to click, extract data, or manipulate the page, optionally scoped to a specific element.
Instructions
Execute JavaScript in the page context via Playwright's page.evaluate(). Use for interacting with elements not in the accessibility snapshot (portal divs, framework overlays, shadow DOM). Can run arbitrary JS — click hidden elements, extract data, manipulate the DOM. Optionally scope to a specific element via ref.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | JavaScript expression or function body to evaluate in the browser. Can be a simple expression like `document.title` or a function like `() => document.querySelector('.menu').click()`. If ref is provided, receives the element as first argument: `(el) => el.textContent`. | |
| ref | No | Optional element reference from snapshot (e.g., 'e1'). If provided, the expression receives the DOM element as its first argument. | |
| targetId | No | Target ID of the tab |