Skip to main content
Glama

evaluate_javascript

Execute custom JavaScript code within a browser context using the MCP Browser Server, enabling automation for web interactions, data extraction, and dynamic content manipulation.

Instructions

Execute JavaScript in the browser context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scriptYesJavaScript code to execute

Implementation Reference

  • The handler function for evaluate_javascript tool. It checks for currentPage, parses args with schema, evaluates the JS script on the page using Playwright's evaluate method, and returns the result as JSON stringified text.
    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)}` } ] }; }
  • Defines the input schema for the evaluate_javascript tool using Zod, requiring a 'script' string.
    const EvaluateJavaScriptSchema = z.object({ script: z.string() });
  • src/index.ts:281-294 (registration)
    Registers the evaluate_javascript tool in the list of available tools, including 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'] } },

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

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