Skip to main content
Glama
ztobs
by ztobs

execute_js

Execute JavaScript on webpages to automate tasks, interact with elements, or modify content. Provides a URL and script input for targeted browser automation.

Instructions

Execute JavaScript code on a webpage

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
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")
urlYesThe URL to navigate to

Implementation Reference

  • Core handler logic for the 'execute_js' tool. Validates inputs, uses an LLM agent to navigate to the URL and execute optional steps, then runs the JavaScript script on the browser page.
    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() elif command == 'get_console_logs':
  • src/index.ts:192-213 (registration)
    Registers the 'execute_js' tool with the MCP server in the listTools response, including its name, description, and input schema.
    { 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 schema enforcement for 'execute_js' tool arguments in the callToolRequest handler.
    if (request.params.name === 'execute_js' && typeof args.script !== 'string') { throw new McpError( ErrorCode.InvalidParams, 'Script must be a string' ); }
  • Processes the result from the Python handler for 'execute_js' (falls into the else clause) and formats it for MCP response.
    } else { return { content: [ { type: 'text', text: JSON.stringify(result.result, null, 2), }, ], };

Other Tools

Related 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