Skip to main content
Glama

evaluate_javascript

Execute JavaScript code directly in the browser to manipulate page content, extract data, or run custom scripts for automated testing and interaction.

Instructions

Execute JavaScript in the browser context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • Zod schema for evaluate_javascript input validation, defining a required 'script' string parameter.
    const EvaluateJavaScriptSchema = z.object({
      script: z.string()
    });
  • src/index.ts:281-294 (registration)
    Tool registration for 'evaluate_javascript' in the ListToolsRequestSchema handler, declaring name, description, and input schema.
    {
      name: 'evaluate_javascript',
      description: 'Execute JavaScript in the browser context',
      inputSchema: {
        type: 'object',
        properties: {
          script: {
            type: 'string',
            description: 'JavaScript code to execute'
          }
        },
        required: ['script']
      }
    },
  • Handler for 'evaluate_javascript' tool call. Parses args with the schema, executes the script via Playwright's page.evaluate(), and returns the JSON-stringified result.
    case 'evaluate_javascript': {
      if (!currentPage) {
        throw new Error('No browser page available. Launch a browser first.');
      }
    
      const params = EvaluateJavaScriptSchema.parse(args);
      const result = await currentPage.evaluate(params.script);
    
      return {
        content: [
          {
            type: 'text',
            text: `JavaScript result: ${JSON.stringify(result, null, 2)}`
          }
        ]
      };
    }
Behavior2/5

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

With no annotations, the description must disclose behavioral traits. It only says 'Execute JavaScript in the browser context,' omitting details about what the execution environment supports (e.g., DOM access, async, returns), potential side effects, or error handling. 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.

Conciseness4/5

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

The description is a single sentence that clearly conveys the tool's purpose. It is front-loaded and contains no unnecessary words, but it could benefit from additional context without being verbose.

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, the description is too minimal. It lacks information about return values, permissions, and side effects, making it incomplete for an agent to use safely and effectively.

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 single parameter 'script' has a schema description ('JavaScript code to execute'). The tool description adds no extra meaning beyond the schema, so a baseline score of 3 is appropriate.

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

Purpose5/5

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

The description clearly states the action ('Execute'), the resource ('JavaScript'), and the context ('in the browser context'). This distinguishes it from sibling tools like click_element and navigate, which perform different actions.

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?

No guidance is provided on when to use this tool versus alternatives, nor are there any exclusions or prerequisites mentioned. The description simply states the action without context.

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/Wladastic/mcp-browser-server'

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