browser_screenshot
Capture a screenshot of the current browser page. Save to a specified path or return base64 data for further processing.
Instructions
Take a screenshot of the current page
Input 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:483-523 (registration)The tool 'browser_screenshot' is registered using server.tool() with a Zod schema for an optional outputPath parameter, and a handler that delegates to ActionService.takeScreenshot().
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}`, }, ], }; } } ); - src/tools/actionTools.ts:492-522 (handler)The handler function that executes the screenshot logic: gets the driver from stateManager, creates ActionService, calls takeScreenshot(), then optionally saves to file or 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}`, }, ], }; } } - src/tools/actionTools.ts:486-491 (schema)The Zod validation schema for the tool: an optional 'outputPath' string parameter.
{ outputPath: z .string() .optional() .describe('Optional path where to save the screenshot. If not provided, returns base64 data.'), }, - The takeScreenshot() helper method in ActionService which delegates to the Selenium WebDriver's takeScreenshot() method, returning a base64-encoded string.
async takeScreenshot(): Promise<string> { return this.driver.takeScreenshot(); }