screenshot
Capture full-page or element-specific screenshots in specified dimensions, with options for base64 encoding, using browser automation for testing Autoconsent rules.
Instructions
Capture screenshots of the entire page or specific elements
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| encoded | No | If true, capture the screenshot as a base64-encoded data URI (as text) instead of binary image content. Default false. | |
| height | No | Height in pixels (default: 720) | |
| name | Yes | Name for the screenshot | |
| width | No | Width in pixels (default: 1280) |
Implementation Reference
- src/index.ts:233-281 (handler)The handler function for the 'screenshot' tool that captures a screenshot of the page using Puppeteer, optionally encodes it as base64 text, stores it in a map, notifies of resource changes, and returns success message with image or text content.case "screenshot": { const width = args.width ?? 1280; const height = args.height ?? 720; const encoded = args.encoded ?? false; await page.setViewport({ width, height }); const screenshot = await page.screenshot({ encoding: "base64", fullPage: false, }); if (!screenshot) { return { content: [ { type: "text", text: "Screenshot failed", }, ], isError: true, }; } screenshots.set(args.name, screenshot as string); server.notification({ method: "notifications/resources/list_changed", }); return { content: [ { type: "text", text: `Screenshot '${args.name}' taken at ${width}x${height}`, } as TextContent, encoded ? ({ type: "text", text: `data:image/png;base64,${screenshot}`, } as TextContent) : ({ type: "image", data: screenshot, mimeType: "image/png", } as ImageContent), ], isError: false, }; }
- src/index.ts:41-64 (registration)Registers the 'screenshot' tool in the TOOLS array with its description and input schema definition.{ name: "screenshot", description: "Capture screenshots of the entire page or specific elements", inputSchema: { type: "object", properties: { name: { type: "string", description: "Name for the screenshot" }, width: { type: "number", description: "Width in pixels (default: 1280)", }, height: { type: "number", description: "Height in pixels (default: 720)", }, encoded: { type: "boolean", description: "If true, capture the screenshot as a base64-encoded data URI (as text) instead of binary image content. Default false.", }, }, required: ["name"], }, },
- src/index.ts:44-63 (schema)Defines the input schema for the 'screenshot' tool, specifying parameters like name (required), width, height, and encoded.inputSchema: { type: "object", properties: { name: { type: "string", description: "Name for the screenshot" }, width: { type: "number", description: "Width in pixels (default: 1280)", }, height: { type: "number", description: "Height in pixels (default: 720)", }, encoded: { type: "boolean", description: "If true, capture the screenshot as a base64-encoded data URI (as text) instead of binary image content. Default false.", }, }, required: ["name"], },
- src/index.ts:176-176 (helper)Global Map to store screenshot base64 data keyed by name, used by the handler and resource handlers.const screenshots = new Map<string, string>();