pilot_screenshot
Capture screenshots of web pages or specific elements using browser automation. Specify full-page captures, element references, or custom clip regions for precise documentation and analysis.
Instructions
Take a screenshot of the page or a specific element.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ref | No | Element ref or CSS selector to screenshot | |
| full_page | No | Capture full page (default: true) | |
| output_path | No | Output file path | |
| clip | No | Clip region {x, y, width, height} |
Implementation Reference
- src/tools/visual.ts:42-70 (handler)Handler function for pilot_screenshot which takes a screenshot using Playwright and returns it as an MCP image content.
async ({ ref, full_page, output_path, clip }) => { await bm.ensureBrowser(); try { const page = bm.getPage(); const screenshotPath = output_path || path.join(TEMP_DIR, 'pilot-screenshot.png'); if (ref) { const resolved = await bm.resolveRef(ref); const locator = 'locator' in resolved ? resolved.locator : page.locator(resolved.selector); await locator.screenshot({ path: screenshotPath, timeout: 5000 }); } else if (clip) { await page.screenshot({ path: screenshotPath, clip }); } else { await page.screenshot({ path: screenshotPath, fullPage: full_page !== false }); } const imageData = fs.readFileSync(screenshotPath); const base64 = imageData.toString('base64'); return { content: [ { type: 'text' as const, text: `Screenshot saved: ${screenshotPath}` }, { type: 'image' as const, data: base64, mimeType: 'image/png' }, ], }; } catch (err) { return { content: [{ type: 'text' as const, text: wrapError(err) }], isError: true }; } } - src/tools/visual.ts:31-41 (schema)Input schema for pilot_screenshot tool.
{ ref: z.string().optional().describe('Element ref or CSS selector to screenshot'), full_page: z.boolean().optional().describe('Capture full page (default: true)'), output_path: z.string().optional().describe('Output file path'), clip: z.object({ x: z.number(), y: z.number(), width: z.number(), height: z.number(), }).optional().describe('Clip region {x, y, width, height}'), }, - src/tools/visual.ts:28-30 (registration)Full registration of the pilot_screenshot tool.
server.tool( 'pilot_screenshot', 'Take a screenshot of the page or a specific element.',