browser_screenshot
Capture screenshots of web pages or specific elements using parallel browser instances. Supports PNG and JPEG formats with adjustable quality for precise output.
Instructions
Take a screenshot of the page or element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fullPage | No | Whether to capture the full page | |
| instanceId | Yes | Instance ID | |
| quality | No | Image quality (1-100, JPEG only) | |
| selector | No | Element selector (capture specific element) | |
| type | No | Image format | png |
Implementation Reference
- src/tools.ts:890-933 (handler)The core handler function that executes the browser_screenshot tool logic: retrieves the browser instance, captures screenshot of page or element, encodes as base64, and returns ToolResult.private async screenshot(instanceId: string, options: ScreenshotOptions, selector?: string): Promise<ToolResult> { const instance = this.browserManager.getInstance(instanceId); if (!instance) { return { success: false, error: `Instance ${instanceId} not found` }; } try { let screenshotData: Buffer; if (selector) { const element = await instance.page.$(selector); if (!element) { return { success: false, error: `Element not found: ${selector}`, instanceId }; } screenshotData = await element.screenshot({ type: options.type, quality: options.type === 'jpeg' ? options.quality : undefined }); } else { screenshotData = await instance.page.screenshot({ fullPage: options.fullPage, type: options.type, quality: options.type === 'jpeg' ? options.quality : undefined, clip: options.clip }); } return { success: true, data: { screenshot: screenshotData.toString('base64'), type: options.type, selector }, instanceId }; } catch (error) { return { success: false, error: `Screenshot failed: ${error instanceof Error ? error.message : error}`, instanceId }; } }
- src/tools.ts:359-394 (schema)The tool definition including name, description, and detailed inputSchema for parameter validation in MCP.{ name: 'browser_screenshot', description: 'Take a screenshot of the page or element', inputSchema: { type: 'object', properties: { instanceId: { type: 'string', description: 'Instance ID' }, fullPage: { type: 'boolean', description: 'Whether to capture the full page', default: false }, selector: { type: 'string', description: 'Element selector (capture specific element)' }, type: { type: 'string', enum: ['png', 'jpeg'], description: 'Image format', default: 'png' }, quality: { type: 'number', description: 'Image quality (1-100, JPEG only)', minimum: 1, maximum: 100, default: 80 } }, required: ['instanceId'] } },
- src/tools.ts:562-568 (registration)Dispatch in executeTools method that maps 'browser_screenshot' tool calls to the screenshot handler.case 'browser_screenshot': return await this.screenshot(args.instanceId, { fullPage: args.fullPage || false, type: args.type || 'png', quality: args.quality || 80 }, args.selector);
- src/server.ts:40-45 (registration)MCP server handler for listing tools, which provides the browser_screenshot schema via BrowserTools.getTools().this.server.setRequestHandler(ListToolsRequestSchema, async () => { const tools = this.browserTools.getTools(); return { tools: tools, }; });
- src/server.ts:48-52 (registration)MCP server handler for calling tools, which delegates to BrowserTools.executeTools for browser_screenshot execution.this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { const result = await this.browserTools.executeTools(name, args || {});