Skip to main content
Glama

screenshot_by_uid

Capture screenshots of specific webpage elements by their unique identifier. Use this tool to take base64 PNG images of individual elements for testing, debugging, or documentation purposes.

Instructions

Capture element screenshot by UID as base64 PNG.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uidYesElement UID from snapshot

Implementation Reference

  • MCP tool handler: validates uid arg, gets Firefox instance, calls takeScreenshotByUid, handles special errors for stale UIDs, builds response with size info
    export async function handleScreenshotByUid(args: unknown): Promise<McpToolResponse> { try { const { uid } = args as { uid: string }; if (!uid || typeof uid !== 'string') { throw new Error('uid required'); } const { getFirefox } = await import('../index.js'); const firefox = await getFirefox(); try { const base64Png = await firefox.takeScreenshotByUid(uid); if (!base64Png || typeof base64Png !== 'string') { throw new Error('Invalid screenshot data'); } return buildScreenshotResponse(base64Png, uid); } catch (error) { const errorMsg = (error as Error).message; // Concise error for stale UIDs if ( errorMsg.includes('stale') || errorMsg.includes('Snapshot') || errorMsg.includes('UID') || errorMsg.includes('not found') ) { throw new Error(`${uid} stale/invalid. Call take_snapshot first.`); } throw error; } } catch (error) { return errorResponse(error as Error); } }
  • Tool schema definition: specifies name, description, and inputSchema requiring 'uid' string
    export const screenshotByUidTool = { name: 'screenshot_by_uid', description: 'Capture element screenshot by UID as base64 PNG.', inputSchema: { type: 'object', properties: { uid: { type: 'string', description: 'Element UID from snapshot', }, }, required: ['uid'], }, };
  • src/index.ts:140-140 (registration)
    Registers the handler function in the toolHandlers Map used by the MCP server
    ['screenshot_by_uid', tools.handleScreenshotByUid],
  • src/index.ts:184-184 (registration)
    Includes the tool definition in the allTools array returned by listTools
    tools.screenshotByUidTool,
  • Core helper: resolves UID to WebElement, scrolls into view, takes element screenshot using Selenium WebElement.takeScreenshot()
    async takeScreenshotByUid(uid: string): Promise<string> { if (!this.resolveUid) { throw new Error( 'takeScreenshotByUid: resolveUid callback not set. Ensure snapshot is initialized.' ); } const el = await this.resolveUid(uid); // Scroll element into view await this.driver.executeScript( 'arguments[0].scrollIntoView({block: "center", inline: "center"});', el ); // Wait for scroll to complete await new Promise((resolve) => setTimeout(resolve, 100)); // Take screenshot of element (Selenium automatically crops to element bounds) return await el.takeScreenshot(); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/freema/firefox-devtools-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server