screenshot
Capture browser screenshots for web automation tasks. Specify viewport, element, or full page captures with Playwright integration.
Instructions
Take a screenshot
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| type | No | ||
| selector | No |
Implementation Reference
- src/controllers/playwright.ts:210-237 (handler)Core implementation of the screenshot tool in PlaywrightController. Handles screenshot types: element, viewport, full page. Uses Playwright API to capture and save to path.async screenshot(options: ScreenshotOptions): Promise<void> { try { if (!this.isInitialized() || !this.state.page) { throw new Error('Browser not initialized'); } this.log('Taking screenshot', options); if (options.type === 'element' && options.selector) { const element = await this.state.page.$(options.selector); if (!element) { throw new Error('Element not found'); } await element.screenshot({ path: options.path }); } else if (options.type === 'viewport') { await this.state.page.screenshot({ path: options.path }); } else { await this.state.page.screenshot({ path: options.path, fullPage: true }); } this.log('Screenshot saved to', options.path); } catch (error: any) { console.error('Screenshot error:', error); throw new BrowserError( 'Failed to take screenshot', 'Check if the path is writable and element exists (if capturing element)' ); } }
- src/server.ts:69-81 (schema)MCP Tool schema for 'screenshot' defining input parameters: path (required), type (viewport/element/page), selector.const SCREENSHOT_TOOL: Tool = { name: "screenshot", description: "Take a screenshot", inputSchema: { type: "object", properties: { path: { type: "string" }, type: { type: "string", enum: ["viewport", "element", "page"] }, selector: { type: "string" } }, required: ["path"] } };
- src/server.ts:521-521 (registration)Registration of SCREENSHOT_TOOL in the tools dictionary provided to MCP server capabilities.screenshot: SCREENSHOT_TOOL,
- src/server.ts:666-677 (handler)MCP callTool dispatch case for 'screenshot' tool: validates path arg and calls playwrightController.screenshot.case 'screenshot': { if (!args.path) { return { content: [{ type: "text", text: "Path is required" }], isError: true }; } await playwrightController.screenshot(args as any); return { content: [{ type: "text", text: "Screenshot taken successfully" }] }; }
- src/types/index.ts:20-24 (schema)TypeScript interface defining ScreenshotOptions for type safety in the handler.export interface ScreenshotOptions { path: string; type?: 'element' | 'page' | 'viewport'; selector?: string; }