Skip to main content
Glama

browser_evaluate

Execute JavaScript code within browser page contexts to automate interactions, extract data, or modify content across multiple parallel browser instances.

Instructions

Execute JavaScript code in the page context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instanceIdYesInstance ID
scriptYesJavaScript code to execute

Implementation Reference

  • Core handler that executes JavaScript in the browser page using Playwright's page.evaluate(script). Handles instance lookup, execution, and error handling.
    private async evaluate(instanceId: string, script: string): Promise<ToolResult> { const instance = this.browserManager.getInstance(instanceId); if (!instance) { return { success: false, error: `Instance ${instanceId} not found` }; } try { const result = await instance.page.evaluate(script); return { success: true, data: { script, result }, instanceId }; } catch (error) { return { success: false, error: `Evaluate failed: ${error instanceof Error ? error.message : error}`, instanceId }; }
  • Tool schema definition including name, description, and input schema requiring instanceId and script.
    { name: 'browser_evaluate', description: 'Execute JavaScript code in the page context', inputSchema: { type: 'object', properties: { instanceId: { type: 'string', description: 'Instance ID' }, script: { type: 'string', description: 'JavaScript code to execute', } }, required: ['instanceId', 'script'] } },
  • src/server.ts:40-45 (registration)
    MCP server registration for listing tools; returns all BrowserTools including browser_evaluate schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => { const tools = this.browserTools.getTools(); return { tools: tools, }; });
  • src/server.ts:48-53 (registration)
    MCP server handler for tool calls; delegates execution to BrowserTools.executeTools which handles browser_evaluate case.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { const result = await this.browserTools.executeTools(name, args || {});
  • src/tools.ts:575-576 (registration)
    Dispatch case in executeTools method that routes browser_evaluate calls to the evaluate handler.
    case 'browser_evaluate': return await this.evaluate(args.instanceId, args.script);

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/sailaoda/concurrent-browser-mcp'

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