getImages
Extract all images from a webpage using PlayMCP's automation capabilities. Ideal for web scraping, testing, or saving visual content efficiently.
Instructions
Get all images from the current page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/controllers/playwright.ts:415-437 (handler)The core handler function in PlaywrightController class that evaluates all img elements on the current page and extracts their src, alt, title, width, and height attributes.async getImages(): Promise<Array<{src: string, alt?: string, title?: string, width?: number, height?: number}>> { try { if (!this.isInitialized()) { throw new Error('Browser not initialized'); } this.log('Getting page images'); const images = await this.state.page?.evaluate(() => { const imgElements = Array.from(document.querySelectorAll('img')); return imgElements.map(img => ({ src: (img as HTMLImageElement).src, alt: img.getAttribute('alt') || undefined, title: img.getAttribute('title') || undefined, width: (img as HTMLImageElement).naturalWidth || undefined, height: (img as HTMLImageElement).naturalHeight || undefined })); }); this.log('Images retrieved:', images?.length); return images || []; } catch (error: any) { console.error('Get images error:', error); throw new BrowserError('Failed to get images', 'Check if the page is loaded'); } }
- src/server.ts:163-171 (schema)The Tool schema definition for 'getImages', including name, description, and inputSchema (no required parameters).const GET_IMAGES_TOOL: Tool = { name: "getImages", description: "Get all images from the current page", inputSchema: { type: "object", properties: {}, required: [] } };
- src/server.ts:530-530 (registration)Registration of the getImages tool in the tools object used for MCP capabilities.getImages: GET_IMAGES_TOOL,
- src/server.ts:733-738 (registration)The dispatch handler in callTool request that invokes the playwrightController.getImages() and returns the result in MCP format.case 'getImages': { const images = await playwrightController.getImages(); return { content: [{ type: "text", text: JSON.stringify(images, null, 2) }] }; }