Skip to main content
Glama
ztobs

Browser Use Server

by ztobs

execute_js

Execute JavaScript code on webpages to automate browser interactions, modify content, or extract data through programmatic control.

Instructions

Execute JavaScript code on a webpage

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL to navigate to
scriptYesThe JavaScript code to execute
stepsNoComma-separated actions or sentences describing steps to take after page load (e.g., "click #submit, scroll down" or "Fill the login form and submit")

Implementation Reference

  • Handler for the 'execute_js' command. Navigates to the specified URL using an AI agent for optional steps, then executes the provided JavaScript script on the page and returns the result.
    elif command == 'execute_js':
        if not args.get('url') or not args.get('script'):
            return {
                'success': False,
                'error': 'URL and script are required for execute_js command'
            }
    
        task = f"1. Go to {args['url']}"
        if args.get('steps'):
            steps = args['steps'].split(',')
            for i, step in enumerate(steps, 2):
                task += f"\n{i}. {step.strip()}"
            task += f"\n{len(steps) + 2}. Execute JavaScript: {args['script']}"
        else:
            task += f"\n2. Execute JavaScript: {args['script']}"
        use_vision = os.getenv('USE_VISION', 'false').lower() == 'true'
        agent = Agent(task=task, llm=llm, use_vision=use_vision, browser_context=context)
        await agent.run()
    
        try:
            result = await context.execute_javascript(args['script'])
            return {
                'success': True,
                'result': result
            }
        finally:
            await context.close()
  • src/index.ts:192-212 (registration)
    Registration of the 'execute_js' tool in the MCP server, including name, description, and input schema definition.
    {
      name: 'execute_js',
      description: 'Execute JavaScript code on a webpage',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'The URL to navigate to',
          },
          script: {
            type: 'string',
            description: 'The JavaScript code to execute',
          },
          steps: {
            type: 'string',
            description: 'Comma-separated actions or sentences describing steps to take after page load (e.g., "click #submit, scroll down" or "Fill the login form and submit")',
          },
        },
        required: ['url', 'script'],
      },
  • Input validation specifically for the 'execute_js' tool, ensuring the script argument is a string.
    if (request.params.name === 'execute_js' && typeof args.script !== 'string') {
      throw new McpError(
        ErrorCode.InvalidParams,
        'Script must be a string'
      );
    }
  • Core execution of the JavaScript using the browser context's execute_javascript method.
        result = await context.execute_javascript(args['script'])
        return {
            'success': True,
            'result': result
        }
    finally:
        await context.close()
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 lacks details on permissions needed, potential side effects (e.g., page modifications), error handling, or execution environment. This is inadequate for a tool that performs code execution.

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 no wasted words. It's front-loaded and efficiently communicates the core function 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 JavaScript on a webpage, the lack of annotations, and no output schema, the description is insufficient. It doesn't cover behavioral aspects like safety, return values, or error conditions, leaving significant gaps for an agent to use this tool 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?

Schema description coverage is 100%, so the schema already documents all parameters (url, script, steps). The description adds no additional meaning or context beyond what's in the schema, such as examples or constraints, but doesn't contradict it either.

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 target ('on a webpage'), which is specific and unambiguous. However, it doesn't explicitly differentiate from sibling tools like get_console_logs or get_html, which also interact with webpages but for different purposes.

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 get_html or screenshot, nor does it mention prerequisites or constraints. It simply states what the tool does without context for selection.

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/ztobs/cline-browser-use-mcp'

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