browser_execute_script
Execute JavaScript expressions in the active page to automate tasks, extract data, or manipulate DOM. Wrap multi-step logic in an IIFE to return results.
Instructions
Execute JavaScript in the current page. IMPORTANT: the parameter is code (NOT script — though that alias is accepted), and it must be an EXPRESSION, not statements: use an IIFE (() => { ...; return x; })(). Top-level return is a syntax error (the handler wraps code in parentheses).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | JavaScript EXPRESSION to evaluate in page context. For multi-statement logic use an IIFE: (() => { ...; return result; })() |