evaluate
Execute JavaScript code directly on web pages to automate interactions, extract data, or modify content during browser automation sessions.
Instructions
Run JavaScript code on the page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| script | Yes | JavaScript code to execute |
Implementation Reference
- tools-playwright.js:242-245 (handler)Handler function for the 'evaluate' tool. Takes a JavaScript script as input and delegates execution to the browser instance, returning the result in a structured format.handler: async ({ script }) => { const result = await browser.evaluate(script); return { success: true, data: { result }, message: 'JavaScript executed successfully' }; }
- tools-playwright.js:235-241 (schema)Input schema for the 'evaluate' tool, defining the required 'script' parameter as a string.inputSchema: { type: 'object', properties: { script: { type: 'string', description: 'JavaScript code to execute' } }, required: ['script'] },
- tools-playwright.js:232-246 (registration)Complete tool object registration for 'evaluate' in the createPlaywrightTools function's return array, including name, description, schema, and handler.{ name: 'evaluate', description: 'Run JavaScript code on the page', inputSchema: { type: 'object', properties: { script: { type: 'string', description: 'JavaScript code to execute' } }, required: ['script'] }, handler: async ({ script }) => { const result = await browser.evaluate(script); return { success: true, data: { result }, message: 'JavaScript executed successfully' }; } },
- browser.js:126-129 (helper)Supporting 'evaluate' method in SimpleBrowser class that ensures the browser is launched and executes the provided JavaScript on the current page using Playwright's page.evaluate.async evaluate(script) { await this.ensureLaunched(); return await this.page.evaluate(script); }