Skip to main content
Glama

puppeteer_evaluate

Execute JavaScript in a browser console to automate web interactions, extract data, or manipulate web pages using the MCP Puppeteer Linux Server.

Instructions

Execute JavaScript in the browser console

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • Handler for puppeteer_evaluate: evaluates the provided JavaScript script in the browser page context, captures console logs by overriding console methods, and returns the result along with captured logs.
    case "puppeteer_evaluate": try { const result = await page.evaluate((script) => { const logs = []; const originalConsole = { ...console }; ['log', 'info', 'warn', 'error'].forEach(method => { console[method] = (...args) => { logs.push(`[${method}] ${args.join(' ')}`); originalConsole[method](...args); }; }); try { const result = eval(script); Object.assign(console, originalConsole); return { result, logs }; } catch (error) { Object.assign(console, originalConsole); throw error; } }, args.script); return { content: [ { type: "text", text: `Execution result:\n${JSON.stringify(result.result, null, 2)}\n\nConsole output:\n${result.logs.join('\n')}`, }, ], isError: false, }; } catch (error) { return { content: [{ type: "text", text: `Script execution failed: ${error.message}`, }], isError: true, }; }
  • Input schema definition for the puppeteer_evaluate tool, specifying the 'script' parameter.
    { name: "puppeteer_evaluate", description: "Execute JavaScript in the browser console", inputSchema: { type: "object", properties: { script: { type: "string", description: "JavaScript code to execute" }, }, required: ["script"], }, },
  • index.ts:451-451 (registration)
    Registration of the generic tool call handler that dispatches to handleToolCall based on tool name, including puppeteer_evaluate.
    server.setRequestHandler(CallToolRequestSchema, async (request) => handleToolCall(request.params.name, request.params.arguments ?? {}));
  • index.ts:447-449 (registration)
    Registration of the list tools handler that exposes the TOOLS array containing puppeteer_evaluate.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS, }));

Other Tools

Related Tools

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/PhialsBasement/MCP-Puppeteer-Linux'

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