Skip to main content
Glama

puppeteer_evaluate

Execute JavaScript code directly in a browser console to automate web interactions, extract data, or manipulate page content through browser automation.

Instructions

Execute JavaScript in the browser console

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • The handler logic for the puppeteer_evaluate tool. Evaluates JavaScript in the browser page context, overrides console methods to capture logs, and returns the execution result along with captured console output.
    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 for the puppeteer_evaluate tool, defining the required 'script' parameter as a string.
    inputSchema: { type: "object", properties: { script: { type: "string", description: "JavaScript code to execute" }, }, required: ["script"], },
  • index.ts:174-184 (registration)
    Tool registration object in the TOOLS array, including name, description, and input schema. This array is returned by the listTools handler.
    { name: "puppeteer_evaluate", description: "Execute JavaScript in the browser console", inputSchema: { type: "object", properties: { script: { type: "string", description: "JavaScript code to execute" }, }, required: ["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/PhialsBasement/MCP-Puppeteer-Linux'

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