Skip to main content
Glama

browser_execute_script

Execute JavaScript code within the current web page to automate browser interactions, manipulate page elements, or perform custom web testing operations.

Instructions

Execute JavaScript in the context of the current page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • The complete tool registration block for 'browser_execute_script', serving as the handler function that validates input with Zod schema, executes the script via ActionService, and returns success/error responses.
    server.tool( 'browser_execute_script', 'Execute JavaScript in the context of the current page', { script: z.string().describe('JavaScript code to execute'), }, async ({ script }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); const result = await actionService.executeScript(script); return { content: [{ type: 'text', text: `Script executed successfully: ${result}` }], }; } catch (e) { return { content: [ { type: 'text', text: `Error executing script: ${(e as Error).message}`, }, ], }; } } );
  • Input schema for the browser_execute_script tool using Zod.
    { script: z.string().describe('JavaScript code to execute'), },
  • Core helper method in ActionService that executes arbitrary JavaScript on the current page using Selenium WebDriver's executeScript.
    async executeScript(script: string, args = []): Promise<any> { return this.driver.executeScript(script, ...args); }
  • Invocation of registerActionTools within registerAllTools, which registers the action tools including browser_execute_script.
    registerActionTools(server, stateManager);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/pshivapr/selenium-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server