execute_js
Run custom JavaScript in a browser page or iframe to capture return values, and replay HTTP requests using the page session for authenticated fetches.
Instructions
Execute custom JavaScript in the page context with async support, return value capture, and iframe targeting. Also supports action="fetch" to replay HTTP requests with the page session (cookies/auth inherited, 30s timeout, structured status/headers/body output).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | No | URL for fetch action | |
| body | No | Body for fetch action (POST/PUT) | |
| code | No | JavaScript code to execute in the page context (required unless action="fetch") | |
| async | No | Run as a background job: returns a jobId immediately instead of blocking; poll async_job for the result. Inside the job the code is wrapped in an async function, so top-level await works. | |
| action | No | execute: run JS code; fetch: replay an HTTP request with page session | execute |
| iframe | No | Execute inside a specific iframe (0 = main frame, 1+ = iframe by index) | |
| method | No | HTTP method for fetch action | GET |
| headers | No | Headers for fetch action | |
| timeout | No | ||
| returnValue | No | Return the result of the expression | |
| waitForIframe | No | Wait for the iframe to finish loading before executing | |
| iframeSelector | No | Execute inside iframe matched by CSS selector |