Execute JavaScript
browser_executeExecute JavaScript in the current page to handle complex browser interactions and return the result. Use it for jQuery widgets, DOM changes, page variables, or custom events.
Instructions
Execute arbitrary JavaScript code on the current page and return the result. Use this for complex interactions that other tools cannot handle: jQuery/Select2 dropdowns (e.g. jQuery("#select").val("value").trigger("change")), reading JavaScript variables, calling page functions, manipulating complex widgets, dispatching custom events, or any DOM manipulation. The code runs in the page context with full access to window, document, jQuery, etc. Return a value from your code and it will be sent back as the result. Examples: Set Select2 dropdown: 'jQuery("#project").val("123").trigger("change")' | Read a value: 'document.querySelector("#total").textContent' | Fill multiple fields: 'jQuery("#name").val("John"); jQuery("#email").val("john@example.com"); "done"' | Trigger form submit: 'document.querySelector("form").submit()' | Check if element exists: '!!document.querySelector(".success-message")'
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | JavaScript code to execute in the page context. Has full access to window, document, jQuery ($), and all page globals. The return value of the last expression is sent back as the result. For async operations, return a Promise. | |
| mode | No | Force a specific mode. Defaults to extension. | |
| sessionId | No | Puppeteer session ID for headless mode. Skips mode selection. |