Skip to main content
Glama

safari_execute_script

Execute JavaScript code within Safari browser sessions to automate tasks, manipulate web content, and interact with page elements programmatically.

Instructions

Execute JavaScript in the browser context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSession identifier
scriptYesJavaScript code to execute
argsNoArguments to pass to the script

Implementation Reference

  • Core implementation of the tool: retrieves the Safari session and executes the JavaScript script using Selenium WebDriver's executeScript method, with error handling.
    async executeScript(sessionId: string, script: string, args: any[] = []): Promise<any> { const session = this.getSession(sessionId); if (!session) { throw new Error(`Session ${sessionId} not found`); } try { return await session.driver.executeScript(script, ...args); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Script execution failed: ${errorMessage}`); } }
  • MCP server-side wrapper for the tool: parses input arguments, delegates to SafariDriverManager, and formats the result as a text response.
    private async executeScript(args: Record<string, any>): Promise<Array<{ type: string; text: string }>> { const { sessionId, script, args: scriptArgs = [] } = args; const result = await this.driverManager.executeScript(sessionId, script, scriptArgs); return [ { type: 'text', text: `Script execution result:\n${JSON.stringify(result, null, 2)}` } ]; }
  • Input schema definition for the safari_execute_script tool, including required sessionId and script, optional args array.
    { name: 'safari_execute_script', description: 'Execute JavaScript in the browser context', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Session identifier' }, script: { type: 'string', description: 'JavaScript code to execute' }, args: { type: 'array', description: 'Arguments to pass to the script' } }, required: ['sessionId', 'script'] } },
  • Tool dispatch/registration in the handleToolCall switch statement, routing calls to the executeScript handler.
    case 'safari_execute_script': return await this.executeScript(args);

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/lxman/safari-mcp-server'

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