browser_take_screenshot
Capture screenshots of web pages or specific elements using Playwright MCP Server. Automate visual documentation, debugging, or content extraction tasks with ease.
Instructions
Take a screenshot of the current page or a specific element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fullPage | No | ||
| selector | No |
Implementation Reference
- src/server.ts:73-106 (handler)The core handler function that implements the browser_take_screenshot tool. It validates input, ensures Playwright connection, captures screenshot of the full page or specified element, encodes it to base64, and returns it in the response.async (params: any) => { try { const input = z.object({ fullPage: z.boolean().optional().default(false), selector: z.string().optional() }).parse(params); await this.playwright.ensureConnected(); const page = this.playwright.getPage(); let screenshot: Buffer; if (input.selector) { const element = await page.locator(input.selector); screenshot = await element.screenshot(); } else { screenshot = await page.screenshot({ fullPage: input.fullPage }); } return { content: [{ type: 'text', text: `Screenshot taken (${screenshot.length} bytes), base64: ${screenshot.toString('base64')}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Screenshot failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
- src/server.ts:63-72 (registration)Registers the browser_take_screenshot tool with the MCP server, providing title, description, and inline input schema.this.server.registerTool( 'browser_take_screenshot', { title: 'Take Screenshot', description: 'Take a screenshot of the current page or a specific element', inputSchema: { fullPage: z.boolean().optional().default(false), selector: z.string().optional() } },
- src/types.ts:18-21 (schema)Zod input schema definition for the browser_take_screenshot tool, defining optional fullPage and selector parameters.export const BrowserTakeScreenshotInputSchema = z.object({ fullPage: z.boolean().optional().default(false), selector: z.string().optional() });
- src/types.ts:60-60 (schema)TypeScript type inferred from the BrowserTakeScreenshotInputSchema for type safety.export type BrowserTakeScreenshotInput = z.infer<typeof BrowserTakeScreenshotInputSchema>;