browser_screenshot
Capture screenshots of web pages for documentation, testing, or monitoring purposes using Selenium WebDriver automation.
Instructions
Take a screenshot of the current page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| outputPath | No | Optional path where to save the screenshot. If not provided, returns base64 data. |
Implementation Reference
- src/tools/actionTools.ts:492-522 (handler)The handler function that executes the browser_screenshot tool logic, using ActionService to capture the screenshot and handle output as base64 or file save.async ({ outputPath }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); const screenshot = await actionService.takeScreenshot(); if (outputPath) { const fs = await import('fs/promises'); await fs.writeFile(outputPath, screenshot, 'base64'); return { content: [{ type: 'text', text: `Screenshot saved to ${outputPath}` }], }; } else { return { content: [ { type: 'text', text: 'Screenshot captured as base64:' }, { type: 'text', text: screenshot }, ], }; } } catch (e) { return { content: [ { type: 'text', text: `Error taking screenshot: ${(e as Error).message}`, }, ], }; } }
- src/tools/actionTools.ts:486-491 (schema)Zod input schema for the browser_screenshot tool, defining optional outputPath parameter.{ outputPath: z .string() .optional() .describe('Optional path where to save the screenshot. If not provided, returns base64 data.'), },
- src/tools/actionTools.ts:483-523 (registration)Registers the browser_screenshot tool with the MCP server using server.tool().server.tool( 'browser_screenshot', 'Take a screenshot of the current page', { outputPath: z .string() .optional() .describe('Optional path where to save the screenshot. If not provided, returns base64 data.'), }, async ({ outputPath }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); const screenshot = await actionService.takeScreenshot(); if (outputPath) { const fs = await import('fs/promises'); await fs.writeFile(outputPath, screenshot, 'base64'); return { content: [{ type: 'text', text: `Screenshot saved to ${outputPath}` }], }; } else { return { content: [ { type: 'text', text: 'Screenshot captured as base64:' }, { type: 'text', text: screenshot }, ], }; } } catch (e) { return { content: [ { type: 'text', text: `Error taking screenshot: ${(e as Error).message}`, }, ], }; } } );
- Supporting method in ActionService that directly calls Selenium WebDriver's takeScreenshot() to capture the page screenshot.async takeScreenshot(): Promise<string> { return this.driver.takeScreenshot(); }