run_javascript
Execute arbitrary JavaScript in the active page to handle operations not covered by standard automation tools, including DOM access, storage reads, and dynamic page manipulation.
Instructions
Evaluate a JavaScript expression in the current page context.
Use this only when the required browser operation cannot be accomplished through the higher-level SeleniumBase tools.
The expression is evaluated through Chrome DevTools Protocol Runtime.evaluate in the currently active page. It executes with access to the page's JavaScript context, including DOM APIs, browser storage, and other same-origin page resources available to JavaScript.
Tool selection: - Prefer click, type_text, select_option, hover_with_action, focus_on, scroll, and other higher-level tools for normal browser interactions. - Prefer get_content, get_attributes, and find_elements for reading page content or element information. - Prefer manage_storage for ordinary localStorage/sessionStorage reads and writes. - Prefer manage_cookies for browser cookie operations. - Use this tool when a required operation needs arbitrary JavaScript that the higher-level tools do not expose.
Args: expression: A JavaScript expression or executable JavaScript code evaluated in the current page. It may reference standard browser globals such as document and window and may use DOM APIs.
Examples:
- "document.title"
- "document.querySelector('button')?.textContent"
- "localStorage.getItem('theme')"
- "document.body.classList.contains('dark')"
- "document.querySelector('#slider').value = '50'"
The expression should produce a value when a result is needed.
JavaScript that returns a Promise is supported and its resolved
value is returned.Returns: The JavaScript evaluation result when it can be serialized and returned across the MCP boundary. Primitive values, arrays, plain objects, and null are generally suitable return values. DOM objects, functions, symbols, and other non-serializable JavaScript values may not be returned directly; extract the needed property or convert the value to a serializable form first.
Security: This provides unrestricted JavaScript execution in the current browser page. It can read or modify page data and interact with the page in ways that bypass the higher-level tool abstractions. Only expose this MCP server to trusted clients.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes |