Skip to main content
Glama

browser_screenshot

Capture screenshots of web pages for documentation, testing, or monitoring purposes using Selenium WebDriver automation.

Instructions

Take a screenshot of the current page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
outputPathNoOptional path where to save the screenshot. If not provided, returns base64 data.

Implementation Reference

  • The handler function that executes the browser_screenshot tool logic, using ActionService to capture the screenshot and handle output as base64 or file save.
    async ({ outputPath }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); const screenshot = await actionService.takeScreenshot(); if (outputPath) { const fs = await import('fs/promises'); await fs.writeFile(outputPath, screenshot, 'base64'); return { content: [{ type: 'text', text: `Screenshot saved to ${outputPath}` }], }; } else { return { content: [ { type: 'text', text: 'Screenshot captured as base64:' }, { type: 'text', text: screenshot }, ], }; } } catch (e) { return { content: [ { type: 'text', text: `Error taking screenshot: ${(e as Error).message}`, }, ], }; } }
  • Zod input schema for the browser_screenshot tool, defining optional outputPath parameter.
    { outputPath: z .string() .optional() .describe('Optional path where to save the screenshot. If not provided, returns base64 data.'), },
  • Registers the browser_screenshot tool with the MCP server using server.tool().
    server.tool( 'browser_screenshot', 'Take a screenshot of the current page', { outputPath: z .string() .optional() .describe('Optional path where to save the screenshot. If not provided, returns base64 data.'), }, async ({ outputPath }) => { try { const driver = stateManager.getDriver(); const actionService = new ActionService(driver); const screenshot = await actionService.takeScreenshot(); if (outputPath) { const fs = await import('fs/promises'); await fs.writeFile(outputPath, screenshot, 'base64'); return { content: [{ type: 'text', text: `Screenshot saved to ${outputPath}` }], }; } else { return { content: [ { type: 'text', text: 'Screenshot captured as base64:' }, { type: 'text', text: screenshot }, ], }; } } catch (e) { return { content: [ { type: 'text', text: `Error taking screenshot: ${(e as Error).message}`, }, ], }; } } );
  • Supporting method in ActionService that directly calls Selenium WebDriver's takeScreenshot() to capture the page screenshot.
    async takeScreenshot(): Promise<string> { return this.driver.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/pshivapr/selenium-mcp'

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