takeScreenshot
Capture a webpage screenshot or a specific element using CSS selectors with this PlayMCP Browser Automation Server tool. Ideal for web testing and documentation.
Instructions
Take a screenshot of the page or specific element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| element | No | CSS selector for element screenshot | |
| fullPage | No | Whether to capture the full scrollable page | |
| path | Yes |
Implementation Reference
- src/controllers/playwright.ts:832-851 (handler)Core implementation of the takeScreenshot tool handler. Uses Playwright to capture screenshot of the full page or specific element and saves to the given path.async takeScreenshot(path: string, options?: {fullPage?: boolean, element?: string}): Promise<void> { try { if (!this.isInitialized() || !this.state.page) { throw new Error('Browser not initialized'); } this.log('Taking screenshot', { path, options }); if (options?.element) { const locator = this.state.page.locator(options.element); await locator.screenshot({ path }); } else { await this.state.page.screenshot({ path, fullPage: options?.fullPage }); } this.log('Screenshot saved'); } catch (error: any) { console.error('Screenshot error:', error); throw new BrowserError('Failed to take screenshot', 'Check if the path is writable'); } }
- src/server.ts:443-461 (schema)Input schema definition for the takeScreenshot tool, specifying parameters: path (required string), fullPage (optional boolean), element (optional string selector).const TAKE_SCREENSHOT_TOOL: Tool = { name: "takeScreenshot", description: "Take a screenshot of the page or specific element", inputSchema: { type: "object", properties: { path: { type: "string" }, fullPage: { type: "boolean", description: "Whether to capture the full scrollable page" }, element: { type: "string", description: "CSS selector for element screenshot" } }, required: ["path"] } };
- src/server.ts:548-548 (registration)Registration of the takeScreenshot tool in the server's tools dictionary.takeScreenshot: TAKE_SCREENSHOT_TOOL,
- src/server.ts:942-956 (handler)MCP server dispatch handler for takeScreenshot tool calls, which invokes the controller method with parsed arguments.case 'takeScreenshot': { if (!args.path) { return { content: [{ type: "text", text: "Path is required" }], isError: true }; } await playwrightController.takeScreenshot(args.path as string, { fullPage: args.fullPage as boolean, element: args.element as string }); return { content: [{ type: "text", text: "Screenshot taken successfully" }] }; }