evaluate
Run JavaScript directly in the browser console using Autoconsent MCP to test and automate consent management platforms, enabling precise interaction with web pages.
Instructions
Execute JavaScript in the browser console
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| script | Yes | JavaScript code to execute |
Implementation Reference
- src/index.ts:332-381 (handler)The handler function for the 'evaluate' tool. It sets up a helper to capture console logs, executes the user-provided JavaScript script in the browser page context, retrieves the execution result and captured console logs, and returns them as text content.case "evaluate": try { await page.evaluate(() => { (window as any).mcpHelper = { logs: [], originalConsole: { ...console }, }; ["log", "info", "warn", "error"].forEach((method) => { (console as any)[method] = (...args: any[]) => { (window as any).mcpHelper.logs.push( `[${method}] ${args.join(" ")}`, ); ((window as any).mcpHelper.originalConsole as any)[method]( ...args, ); }; }); }); const result = await page.evaluate(args.script); const logs = await page.evaluate(() => { Object.assign(console, (window as any).mcpHelper.originalConsole); const logs = (window as any).mcpHelper.logs; delete (window as any).mcpHelper; return logs; }); return { content: [ { type: "text", text: `Execution result:\n${JSON.stringify(result, null, 2)}\n\nConsole output:\n${logs.join("\n")}`, }, ], isError: false, }; } catch (error) { return { content: [ { type: "text", text: `Script execution failed: ${(error as Error).message}`, }, ], isError: true, }; }
- src/index.ts:94-104 (registration)The tool registration in the TOOLS array, including name, description, and input schema. This is used by the ListTools handler to expose the tool.{ name: "evaluate", description: "Execute JavaScript in the browser console", inputSchema: { type: "object", properties: { script: { type: "string", description: "JavaScript code to execute" }, }, required: ["script"], }, },
- src/index.ts:97-103 (schema)Input schema for the 'evaluate' tool, defining the required 'script' parameter.inputSchema: { type: "object", properties: { script: { type: "string", description: "JavaScript code to execute" }, }, required: ["script"], },