Skip to main content
Glama

browser_screenshot

Take a screenshot of the current page or a specific element, with support for full-page capture, element masking, and custom save path.

Instructions

Capture a screenshot of the current page or a specific element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesIdentifier for the screenshot
selectorNoCSS selector for element to capture
fullPageNoCapture full page height
maskNoSelectors for elements to mask
savePathNoPath to save screenshot (default: user's Downloads folder)

Implementation Reference

  • The main handler function for browser_screenshot. Takes a Playwright Page, args, and server. Captures a full-page or element-specific screenshot (PNG), optionally masks elements, saves to disk (defaults to Downloads folder), registers in screenshotRegistry, sends a resource list change notification, and returns the image as base64 in the response.
    async function handleBrowserScreenshot(page: Page, args: any, server: any): Promise<{ toolResult: CallToolResult }> {
      try {
        const options: any = {
          type: "png",
          fullPage: !!args.fullPage
        };
    
        if (args.selector) {
          const element = await page.$(args.selector);
          if (!element) {
            return {
              toolResult: {
                content: [{
                  type: "text",
                  text: `Element not found: ${args.selector}`,
                }],
                isError: true,
              },
            };
          }
          options.element = element;
        }
    
        if (args.mask && Array.isArray(args.mask)) {
          options.mask = await Promise.all(
            args.mask.map(async (selector: string) => await page.$(selector))
          );
        }
    
        const screenshot = await page.screenshot(options);
        const base64Screenshot = screenshot.toString('base64');
        const responseContent: (TextContent | ImageContent)[] = [];
        const savePath = args.savePath || defaultDownloadsPath;
        const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
        const filename = `${args.name}-${timestamp}.png`;
        const filePath = path.join(savePath, filename);
        const dir = path.dirname(filePath);
        if (!fs.existsSync(dir)) {
          fs.mkdirSync(dir, { recursive: true });
        }
    
        fs.writeFileSync(filePath, screenshot);
        responseContent.push({
          type: "text",
          text: `Screenshot saved to: ${filePath}`,
        } as TextContent);
    
        screenshotRegistry.set(args.name, base64Screenshot);
        server.notification({
          method: "notifications/resources/list_changed",
        });
    
        responseContent.push({
          type: "image",
          data: base64Screenshot,
          mimeType: "image/png",
        } as ImageContent);
    
        return {
          toolResult: {
            content: responseContent,
            isError: false,
          },
        };
      } catch (error) {
        return {
          toolResult: {
            content: [{
              type: "text",
              text: `Screenshot failed: ${(error as Error).message}`,
            }],
            isError: true,
          },
        };
      }
    }
  • Schema definition for browser_screenshot tool. Defines input properties: name (required), selector, fullPage, mask (array of CSS selectors), and savePath.
    {
      name: "browser_screenshot",
      description: "Capture a screenshot of the current page or a specific element",
      inputSchema: {
        type: "object",
        properties: {
          name: { type: "string", description: "Identifier for the screenshot" },
          selector: { type: "string", description: "CSS selector for element to capture" },
          fullPage: { type: "boolean", description: "Capture full page height" },
          mask: { 
            type: "array", 
            description: "Selectors for elements to mask",
            items: { type: "string" }
          },
          savePath: { type: "string", description: "Path to save screenshot (default: user's Downloads folder)" }
        },
        required: ["name"]
      }
    },
  • src/tools.ts:54-72 (registration)
    Tool registration in registerTools() function. Returns a Tool object with name, description, and inputSchema for the MCP server.
    {
      name: "browser_screenshot",
      description: "Capture a screenshot of the current page or a specific element",
      inputSchema: {
        type: "object",
        properties: {
          name: { type: "string", description: "Identifier for the screenshot" },
          selector: { type: "string", description: "CSS selector for element to capture" },
          fullPage: { type: "boolean", description: "Capture full page height" },
          mask: { 
            type: "array", 
            description: "Selectors for elements to mask",
            items: { type: "string" }
          },
          savePath: { type: "string", description: "Path to save screenshot (default: user's Downloads folder)" }
        },
        required: ["name"]
      }
    },
  • src/tools.ts:3-12 (registration)
    Registration of browser_screenshot in the BROWSER_TOOLS array, used to determine whether to initialize the browser before executing the tool.
    export const BROWSER_TOOLS = [
      "browser_navigate",
      "browser_screenshot",
      "browser_click",
      "browser_fill",
      "browser_select",
      "browser_hover",
      "browser_evaluate",
      "browser_set_viewport"
    ];
  • Dispatch call in executeToolCall() switch statement that routes browser_screenshot to handleBrowserScreenshot.
    case "browser_screenshot":
      return await handleBrowserScreenshot(activePage!, args, server);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, and the description does not disclose behavioral traits such as whether the capture affects the page state, any authorization requirements, or rate limits. It only states the action, leaving the agent without important context about side effects or constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single well-formed sentence that directly states the tool's purpose. It wastes no words, though it could benefit from slightly more detail without becoming verbose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description is brief and lacks context about return values (e.g., image path), default behavior, or how the tool interacts with other browser tools. Given the five parameters and no output schema, the description should provide more operational context to be fully complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Since schema description coverage is 100%, the baseline is 3. The description does not add additional meaning beyond the parameter names and schema descriptions; for example, it doesn't explain when to use fullPage or mask options more concretely.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool captures a screenshot of the current page or a specific element, which is a specific verb-resource combination. It distinguishes itself from sibling tools like browser_navigate or browser_click by focusing on capture rather than navigation or element interaction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies the tool is used when a screenshot is needed, but it provides no explicit guidance on when to use it versus alternative methods (e.g., browser_evaluate for custom captures) or any exclusions (e.g., not for video capture).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/imprvhub/mcp-browser-agent'

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