Skip to main content
Glama

screenshot_by_uid

Capture PNG screenshots of specific web elements using their unique identifier (UID) for automated testing and debugging workflows.

Instructions

Capture a PNG screenshot of a specific element by UID and return it as a base64 string (without data: prefix). TIP: Take a fresh snapshot if the UID is stale.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uidYesThe UID of the element to screenshot

Implementation Reference

  • Main MCP tool handler: validates UID argument, obtains Firefox instance, captures screenshot via Firefox API, handles errors (esp. stale UIDs), and returns formatted base64 PNG response.
    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 including name, description, and inputSchema for validating the 'uid' parameter.
    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 tool handler in the central toolHandlers Map used by the MCP server.
    ['screenshot_by_uid', tools.handleScreenshotByUid],
  • src/index.ts:184-184 (registration)
    Registers the tool definition in the allTools array returned by listTools.
    tools.screenshotByUidTool,
  • Core helper function in Firefox DOM interactions that resolves UID to WebElement, scrolls into view, and captures element screenshot using Selenium WebDriver.
    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