Skip to main content
Glama

browser_evaluate

Execute JavaScript in browser consoles to test web applications for vulnerabilities during penetration testing.

Instructions

Execute JavaScript in the browser console

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • Handler implementation for the browser_evaluate tool. Evaluates the provided JavaScript script in the browser page context using page.evaluate, temporarily overrides console methods to capture logs, executes the script with eval, restores console, and returns the result object containing execution result and captured logs, or an error message if execution fails.
    case ToolName.BrowserEvaluate:
      try {
        const result = await page.evaluate((script) => {
          const logs: string[] = [];
          const originalConsole = { ...console };
    
          ['log', 'info', 'warn', 'error'].forEach(method => {
            (console as any)[method] = (...args: any[]) => { 
              logs.push(`[${method}] ${args.join(' ')}`);
              (originalConsole as any)[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 as Error).message}`,
            }],
          isError: true,
        };
      }
  • index.ts:155-165 (registration)
    Registration of the browser_evaluate tool in the TOOLS array, specifying its name, description, and input schema which requires a 'script' string parameter.
    {
      name: ToolName.BrowserEvaluate,
      description: "Execute JavaScript in the browser console",
      inputSchema: {
        type: "object",
        properties: {
          script: { type: "string", description: "JavaScript code to execute" },
        },
        required: ["script"],
      },
    },
  • Input schema definition for the browser_evaluate tool, defining the expected arguments structure with a required 'script' property of type string.
    inputSchema: {
      type: "object",
      properties: {
        script: { type: "string", description: "JavaScript code to execute" },
      },
      required: ["script"],
    },
  • index.ts:32-35 (registration)
    Enum definition ToolName.BrowserEvaluate mapped to the tool name string 'browser_evaluate'.
      BrowserEvaluate = "browser_evaluate",
      BrowserUrlReflectedXss = "broser_url_reflected_xss",
      BrowserUrlSqlInjection = "browser_url_sql_injection"
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but offers minimal information. It states what the tool does but doesn't cover critical aspects like security implications (e.g., executing arbitrary JavaScript could be dangerous), execution context (e.g., runs in current page's console), error handling, or output format. For a tool that executes code, this lack of transparency is significant.

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 extremely concise—a single, clear sentence that communicates the core functionality without unnecessary words. It is front-loaded with the essential action and context, making it easy to parse. Every word earns its place, with no redundant information.

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 JavaScript in a browser (a potentially powerful and risky operation), the description is incomplete. With no annotations and no output schema, it fails to address key contextual elements like safety warnings, execution environment details, or what the tool returns (e.g., console output, errors). This leaves significant gaps for an agent to use the tool effectively and safely.

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 'script' parameter clearly documented as 'JavaScript code to execute'. The description adds no additional parameter semantics beyond what the schema provides, such as examples of valid scripts, constraints, or special syntax. However, with only one parameter fully covered by the schema, 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. It distinguishes itself from sibling tools like browser_click or browser_navigate by focusing on code execution rather than UI interaction. However, it doesn't specify what browser context this applies to (e.g., current page, specific tab).

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. It doesn't mention prerequisites (e.g., needing an active browser session), appropriate use cases (e.g., debugging, automation), or when other tools like browser_navigate might be more suitable. The agent must infer usage from the tool name alone.

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/9olidity/MCP-Server-Pentest'

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