evaluate
Execute JavaScript in browser console to test Autoconsent rules and interact with web pages for consent management platform validation.
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-380 (handler)The handler logic for the 'evaluate' tool. It overrides console methods to capture logs, executes the provided JavaScript script using page.evaluate, retrieves the result and captured 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)Registration of the 'evaluate' tool in the TOOLS array, defining its name, description, and input schema.{ 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 definition for the 'evaluate' tool, specifying the required 'script' parameter.inputSchema: { type: "object", properties: { script: { type: "string", description: "JavaScript code to execute" }, }, required: ["script"], },