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"],
      },
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'Execute JavaScript in the browser console' implies a read/write operation, it doesn't specify critical details like execution context (e.g., page vs. frame), error handling, security implications, or whether it returns values. For a tool that can potentially modify page state, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with zero wasted words. It's front-loaded with the core action and context, making it immediately understandable without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of executing arbitrary JavaScript in a browser (which can have side effects, security risks, and varied outputs), the description is inadequate. With no annotations, no output schema, and minimal behavioral context, it fails to prepare an agent for proper use. The description should address execution scope, return values, or error conditions to be complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with the single parameter 'script' clearly documented as 'JavaScript code to execute'. The description adds no additional semantic context beyond this, such as examples of valid scripts or constraints. Since the schema already does the heavy lifting, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Execute JavaScript') and location ('in the browser console'), making the purpose immediately understandable. However, it doesn't differentiate this tool from potential sibling tools that might also execute JavaScript, such as if there were a 'puppeteer_evaluate_inline' or similar variant.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. Given the sibling tools include actions like click, fill, hover, navigate, screenshot, and select, there's no indication whether this tool is for general scripting versus specific interactions, or what scenarios warrant its use over the more specialized siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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