Skip to main content
Glama

browser_evaluate

Execute JavaScript code within browser page contexts to automate interactions, extract data, or modify content across multiple parallel browser instances.

Instructions

Execute JavaScript code in the page context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instanceIdYesInstance ID
scriptYesJavaScript code to execute

Implementation Reference

  • Core handler that executes JavaScript in the browser page using Playwright's page.evaluate(script). Handles instance lookup, execution, and error handling.
    private async evaluate(instanceId: string, script: string): Promise<ToolResult> {
      const instance = this.browserManager.getInstance(instanceId);
      if (!instance) {
        return { success: false, error: `Instance ${instanceId} not found` };
      }
    
      try {
        const result = await instance.page.evaluate(script);
        return {
          success: true,
          data: { script, result },
          instanceId
        };
      } catch (error) {
        return {
          success: false,
          error: `Evaluate failed: ${error instanceof Error ? error.message : error}`,
          instanceId
        };
      }
  • Tool schema definition including name, description, and input schema requiring instanceId and script.
    {
      name: 'browser_evaluate',
      description: 'Execute JavaScript code in the page context',
      inputSchema: {
        type: 'object',
        properties: {
          instanceId: {
            type: 'string',
            description: 'Instance ID'
          },
          script: {
            type: 'string',
            description: 'JavaScript code to execute',
          }
        },
        required: ['instanceId', 'script']
      }
    },
  • src/server.ts:40-45 (registration)
    MCP server registration for listing tools; returns all BrowserTools including browser_evaluate schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => {
      const tools = this.browserTools.getTools();
      return {
        tools: tools,
      };
    });
  • src/server.ts:48-53 (registration)
    MCP server handler for tool calls; delegates execution to BrowserTools.executeTools which handles browser_evaluate case.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      const { name, arguments: args } = request.params;
    
      try {
        const result = await this.browserTools.executeTools(name, args || {});
  • src/tools.ts:575-576 (registration)
    Dispatch case in executeTools method that routes browser_evaluate calls to the evaluate handler.
    case 'browser_evaluate':
      return await this.evaluate(args.instanceId, args.script);
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. It mentions execution but doesn't specify whether this is read-only or has side effects, what permissions are needed, how errors are handled, or what the return format might be. For a tool that executes arbitrary JavaScript, this lack of safety and behavioral context is a significant gap.

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 highly efficient and easy to parse.

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 context, the lack of annotations, and no output schema, the description is insufficient. It doesn't address critical aspects like security implications, error handling, return values, or dependencies on other tools (e.g., requiring browser_create_instance first). This leaves too many unknowns for safe and effective use.

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%, so the schema already documents both parameters (instanceId and script) adequately. The description doesn't add any additional meaning beyond what the schema provides, such as examples of valid scripts or instanceId formats, but it doesn't need to given the high schema coverage.

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 code') and the context ('in the page context'), which distinguishes it from general JavaScript execution tools. However, it doesn't explicitly differentiate from potential sibling tools that might also execute code in different contexts, though the 'page context' specification is helpful.

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 like browser_get_element_text or browser_wait_for_element, nor does it mention prerequisites such as requiring an existing browser instance. It simply states what the tool does without contextual usage information.

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/sailaoda/concurrent-browser-mcp'

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