getImages
Extract all images from web pages for web scraping, testing, or content analysis using browser automation.
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 that executes the getImages tool logic by evaluating JavaScript in the browser context to extract image elements' 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)Defines the tool schema including name, description, and empty input schema (no parameters required).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)Registers the getImages tool in the tools dictionary used for MCP capabilities.getImages: GET_IMAGES_TOOL,
- src/server.ts:733-738 (registration)Dispatches the tool call to the playwrightController.getImages() handler in the MCP request handler.case 'getImages': { const images = await playwrightController.getImages(); return { content: [{ type: "text", text: JSON.stringify(images, null, 2) }] }; }