Skip to main content
Glama

browser_screenshot

Capture screenshots of web pages or specific elements using CSS selectors, with options to mask areas, save to custom paths, or capture full-page content for precise web content documentation.

Instructions

Capture a screenshot of the current page or a specific element

Input Schema

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

Implementation Reference

  • Main handler function for browser_screenshot tool. Captures screenshot of page or element using Playwright, supports selector, fullPage, mask options, saves PNG to Downloads folder with timestamp, encodes to base64 for ImageContent, updates screenshot registry, sends notification, returns text and image content.
    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,
          },
        };
      }
    }
  • Input schema and metadata for the browser_screenshot tool, defining parameters like name (required), selector, fullPage, mask array, 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"]
      }
    },
  • Switch case in executeToolCall function that dispatches browser_screenshot tool calls to the handleBrowserScreenshot handler.
    case "browser_screenshot":
      return await handleBrowserScreenshot(activePage!, args, server);
  • src/tools.ts:5-5 (registration)
    browser_screenshot included in BROWSER_TOOLS constant array, used to identify and initialize browser tools in executor.
    "browser_screenshot",
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the action ('capture') but doesn't specify whether this requires specific permissions, what happens to the screenshot after capture, or any rate limits. The description is minimal and lacks crucial behavioral context for a tool that interacts with browser content.

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

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded with the core action and resource, making it easy to parse quickly. Every word earns its place in conveying essential information.

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

Completeness2/5

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

Given the tool's complexity (interacting with browser content, multiple parameters) and lack of annotations or output schema, the description is insufficient. It doesn't explain what the tool returns (e.g., file path, success status), error conditions, or dependencies on browser state, leaving significant gaps for an AI agent to use it effectively.

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?

Schema description coverage is 100%, so the schema already documents all five parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema, such as explaining trade-offs between fullPage and selector usage or clarifying mask behavior. The baseline score of 3 reflects adequate but not enhanced parameter understanding.

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

Purpose4/5

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

The description clearly states the verb ('capture') and resource ('screenshot') with specific scope ('current page or a specific element'), making the tool's function immediately understandable. However, it doesn't explicitly differentiate from sibling tools like browser_navigate or browser_click, which serve different purposes but operate in the same browser context.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives, nor does it mention prerequisites or context requirements. While it implies usage for capturing screenshots, it lacks explicit direction on scenarios where this tool is preferred over others or when it should be avoided.

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

Related 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