Skip to main content
Glama

take_screenshot

Read-only

Capture screenshots of web pages or specific elements using Chrome DevTools for automation, debugging, and documentation purposes.

Instructions

Take a screenshot of the page or element.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoType of format to save the screenshot as. Default is "png"png
qualityNoCompression quality for JPEG and WebP formats (0-100). Higher values mean better quality but larger file sizes. Ignored for PNG format.
uidNoThe uid of an element on the page from the page content snapshot. If omitted takes a pages screenshot.
fullPageNoIf set to true takes a screenshot of the full page instead of the currently visible viewport. Incompatible with uid.
filePathNoThe absolute path, or a path relative to the current working directory, to save the screenshot to instead of attaching it to the response.

Implementation Reference

  • The main handler function that captures a screenshot of the page or a specific element using Puppeteer. It supports formats (png, jpeg, webp), quality, full page, element by UID, and either attaches the image or saves to file.
    handler: async (request, response, context) => {
      if (request.params.uid && request.params.fullPage) {
        throw new Error('Providing both "uid" and "fullPage" is not allowed.');
      }
    
      let pageOrHandle: Page | ElementHandle;
      if (request.params.uid) {
        pageOrHandle = await context.getElementByUid(request.params.uid);
      } else {
        pageOrHandle = context.getSelectedPage();
      }
    
      const screenshot = await pageOrHandle.screenshot({
        type: request.params.format,
        fullPage: request.params.fullPage,
        quality: request.params.quality,
        optimizeForSpeed: true, // Bonus: optimize encoding for speed
      });
    
      if (request.params.uid) {
        response.appendResponseLine(
          `Took a screenshot of node with uid "${request.params.uid}".`,
        );
      } else if (request.params.fullPage) {
        response.appendResponseLine(
          'Took a screenshot of the full current page.',
        );
      } else {
        response.appendResponseLine(
          "Took a screenshot of the current page's viewport.",
        );
      }
    
      if (request.params.filePath) {
        const file = await context.saveFile(screenshot, request.params.filePath);
        response.appendResponseLine(`Saved screenshot to ${file.filename}.`);
      } else if (screenshot.length >= 2_000_000) {
        const {filename} = await context.saveTemporaryFile(
          screenshot,
          `image/${request.params.format}`,
        );
        response.appendResponseLine(`Saved screenshot to ${filename}.`);
      } else {
        response.attachImage({
          mimeType: `image/${request.params.format}`,
          data: Buffer.from(screenshot).toString('base64'),
        });
      }
    },
  • Zod schema defining the input parameters for the take_screenshot tool: format, quality, uid, fullPage, filePath.
    schema: {
      format: z
        .enum(['png', 'jpeg', 'webp'])
        .default('png')
        .describe('Type of format to save the screenshot as. Default is "png"'),
      quality: z
        .number()
        .min(0)
        .max(100)
        .optional()
        .describe(
          'Compression quality for JPEG and WebP formats (0-100). Higher values mean better quality but larger file sizes. Ignored for PNG format.',
        ),
      uid: z
        .string()
        .optional()
        .describe(
          'The uid of an element on the page from the page content snapshot. If omitted takes a pages screenshot.',
        ),
      fullPage: z
        .boolean()
        .optional()
        .describe(
          'If set to true takes a screenshot of the full page instead of the currently visible viewport. Incompatible with uid.',
        ),
      filePath: z
        .string()
        .optional()
        .describe(
          'The absolute path, or a path relative to the current working directory, to save the screenshot to instead of attaching it to the response.',
        ),
    },
  • The tool is defined and registered using defineTool, including name 'take_screenshot', description, annotations (category DEBUGGING), schema, and handler.
    export const screenshot = defineTool({
      name: 'take_screenshot',
      description: `Take a screenshot of the page or element.`,
      annotations: {
        category: ToolCategories.DEBUGGING,
        readOnlyHint: true,
      },
      schema: {
        format: z
          .enum(['png', 'jpeg', 'webp'])
          .default('png')
          .describe('Type of format to save the screenshot as. Default is "png"'),
        quality: z
          .number()
          .min(0)
          .max(100)
          .optional()
          .describe(
            'Compression quality for JPEG and WebP formats (0-100). Higher values mean better quality but larger file sizes. Ignored for PNG format.',
          ),
        uid: z
          .string()
          .optional()
          .describe(
            'The uid of an element on the page from the page content snapshot. If omitted takes a pages screenshot.',
          ),
        fullPage: z
          .boolean()
          .optional()
          .describe(
            'If set to true takes a screenshot of the full page instead of the currently visible viewport. Incompatible with uid.',
          ),
        filePath: z
          .string()
          .optional()
          .describe(
            'The absolute path, or a path relative to the current working directory, to save the screenshot to instead of attaching it to the response.',
          ),
      },
      handler: async (request, response, context) => {
        if (request.params.uid && request.params.fullPage) {
          throw new Error('Providing both "uid" and "fullPage" is not allowed.');
        }
    
        let pageOrHandle: Page | ElementHandle;
        if (request.params.uid) {
          pageOrHandle = await context.getElementByUid(request.params.uid);
        } else {
          pageOrHandle = context.getSelectedPage();
        }
    
        const screenshot = await pageOrHandle.screenshot({
          type: request.params.format,
          fullPage: request.params.fullPage,
          quality: request.params.quality,
          optimizeForSpeed: true, // Bonus: optimize encoding for speed
        });
    
        if (request.params.uid) {
          response.appendResponseLine(
            `Took a screenshot of node with uid "${request.params.uid}".`,
          );
        } else if (request.params.fullPage) {
          response.appendResponseLine(
            'Took a screenshot of the full current page.',
          );
        } else {
          response.appendResponseLine(
            "Took a screenshot of the current page's viewport.",
          );
        }
    
        if (request.params.filePath) {
          const file = await context.saveFile(screenshot, request.params.filePath);
          response.appendResponseLine(`Saved screenshot to ${file.filename}.`);
        } else if (screenshot.length >= 2_000_000) {
          const {filename} = await context.saveTemporaryFile(
            screenshot,
            `image/${request.params.format}`,
          );
          response.appendResponseLine(`Saved screenshot to ${filename}.`);
        } else {
          response.attachImage({
            mimeType: `image/${request.params.format}`,
            data: Buffer.from(screenshot).toString('base64'),
          });
        }
      },
    });
Behavior3/5

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

Annotations provide readOnlyHint=true, indicating this is a safe read operation. The description adds minimal behavioral context beyond this—it mentions targeting 'page or element' but doesn't disclose side effects like file creation, performance impact, or visual changes. With annotations covering safety, the description adds some value but lacks depth.

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, clear sentence with zero wasted words. It's front-loaded with the core purpose and efficiently conveys the optional element targeting. Every word earns its place, making it easy for an agent to parse quickly.

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?

Given the tool's moderate complexity (5 parameters, no output schema) and rich schema coverage, the description is minimally adequate. It states what the tool does but lacks context on output format (e.g., returns image data or saves to file), error conditions, or dependencies. With annotations covering safety, it meets basic needs but could be more informative.

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%, with detailed parameter documentation. The description doesn't add any parameter semantics beyond what's in the schema—it doesn't explain interactions between parameters like 'uid' and 'fullPage' or provide usage examples. Baseline 3 is appropriate given the comprehensive schema.

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 tool's purpose: 'Take a screenshot of the page or element.' It specifies the verb ('take') and resource ('screenshot') with optional element targeting. However, it doesn't explicitly differentiate from sibling tools like 'take_snapshot' which might have overlapping functionality, preventing a perfect score.

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. It doesn't mention sibling tools like 'take_snapshot' or explain scenarios where screenshotting is preferred over other actions. The agent must infer usage from the tool name alone.

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/SHAY5555-gif/chrome-devtools-mcp'

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