Skip to main content
Glama

browsercat_evaluate

Execute JavaScript code directly in browser console to automate web interactions, extract data, and manipulate page elements through cloud-based browsing.

Instructions

Execute JavaScript in the browser console

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • The handler function for 'browsercat_evaluate' tool. It sets up temporary console logging override in the page context, evaluates the provided JavaScript script, captures and restores console methods, retrieves the result and logs, and returns them formatted as text content.
    case "browsercat_evaluate": try { // Set up console log capture await page.evaluate(() => { window.mcpHelper = { logs: [], originalConsole: { ...console }, }; ['log', 'info', 'warn', 'error'].forEach(method => { (console as any)[method] = (...args: any[]) => { window.mcpHelper.logs.push(`[${method}] ${args.join(' ')}`); (window.mcpHelper.originalConsole as any)[method](...args); }; }); }); const result = await page.evaluate(args.script); // Restore original console and get captured logs const logs = await page.evaluate(() => { Object.assign(console, window.mcpHelper.originalConsole); const logs = window.mcpHelper.logs; delete (window as any).mcpHelper; return logs; }); return { content: [ { type: "text", text: `Execution result:\n${JSON.stringify(result, null, 2)}\n\nConsole output:\n${logs.join('\n')}`, }, ], isError: false, }; } catch (error) { return { content: [{ type: "text", text: `Script execution failed: ${(error as Error).message}`, }], isError: true, }; }
  • The schema definition for the 'browsercat_evaluate' tool, specifying the name, description, and input schema requiring a 'script' string parameter.
    { name: "browsercat_evaluate", description: "Execute JavaScript in the browser console", inputSchema: { type: "object", properties: { script: { type: "string", description: "JavaScript code to execute" }, }, required: ["script"], }, },
  • index.ts:421-423 (registration)
    Registration of all tools including 'browsercat_evaluate' via the ListToolsRequestSchema handler that returns the TOOLS array.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS, }));
  • index.ts:425-427 (registration)
    Registration of the CallToolRequestSchema handler which dispatches to the specific tool handler based on name, including 'browsercat_evaluate'.
    server.setRequestHandler(CallToolRequestSchema, async (request) => handleToolCall(request.params.name, request.params.arguments ?? {}) );

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/pipethedev/browsercat-mcp-server'

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