Skip to main content
Glama

browser_screenshot

Capture webpage screenshots for documentation, testing, or debugging 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

  • MCP server.tool registration and inline handler for 'browser_screenshot'. Defines input schema, executes screenshot capture via ActionService, and returns either file save confirmation or base64 image data in the tool response.
      '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}`,
              },
            ],
          };
        }
      }
    );
  • Zod input schema for the browser_screenshot tool: optional outputPath string.
    {
      outputPath: z
        .string()
        .optional()
        .describe('Optional path where to save the screenshot. If not provided, returns base64 data.'),
    },
  • Core screenshot capture method in ActionService using Selenium WebDriver's driver.takeScreenshot().
    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