evaluate_javascript
Execute JavaScript directly in the browser context to interact with web pages, automate tasks, or extract data using AutoProbeMCP’s browser automation capabilities.
Instructions
Execute JavaScript in the browser context
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| script | Yes | JavaScript code to execute |
Implementation Reference
- src/index.ts:583-599 (handler)Handler for 'evaluate_javascript' tool: checks for current page, parses input with schema, executes the JavaScript using page.evaluate(), and returns the result as a JSON-formatted string.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)}` } ] }; }
- src/index.ts:55-57 (schema)Zod schema defining the input for evaluate_javascript: requires a 'script' string.const EvaluateJavaScriptSchema = z.object({ script: z.string() });
- src/index.ts:281-294 (registration)Tool registration in the list_tools response: defines name, description, and input schema matching the Zod 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'] } },