Skip to main content
Glama

playwright_screenshot

Capture screenshots of web pages or specific elements using browser automation for testing, documentation, or monitoring purposes.

Instructions

Take a screenshot of the current page or a specific element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesName for the screenshot
selectorNoCSS selector for element to screenshot
widthNoWidth in pixels (default: 800)
heightNoHeight in pixels (default: 600)
storeBase64NoStore screenshot in base64 format (default: true)
fullPageNoStore screenshot of the entire page (default: false)
savePngNoSave screenshot as PNG file (default: false)
downloadsDirNoCustom downloads directory path (default: user's Downloads folder)

Implementation Reference

  • The ScreenshotTool class provides the core implementation of the playwright_screenshot tool, including the execute method that captures screenshots of the page or specific elements using Playwright's page.screenshot().
    export class ScreenshotTool extends BrowserToolBase {
      private screenshots = new Map<string, string>();
    
      /**
       * Execute the screenshot tool
       */
      async execute(args: any, context: ToolContext): Promise<ToolResponse> {
        return this.safeExecute(context, async (page) => {
          const screenshotOptions: any = {
            type: args.type || "png",
            fullPage: !!args.fullPage,
          };
    
          if (args.selector) {
            const element = await page.$(args.selector);
            if (!element) {
              return {
                content: [
                  {
                    type: "text",
                    text: `Element not found: ${args.selector}`,
                  },
                ],
                isError: true,
              };
            }
            screenshotOptions.element = element;
          }
    
          // Generate output path
          const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
          const filename = `${args.name || "screenshot"}-${timestamp}.png`;
          const downloadsDir = args.downloadsDir || defaultDownloadsPath;
    
          if (!fs.existsSync(downloadsDir)) {
            fs.mkdirSync(downloadsDir, { recursive: true });
          }
    
          const outputPath = path.join(downloadsDir, filename);
          screenshotOptions.path = outputPath;
    
          const screenshot = await page.screenshot(screenshotOptions);
          const base64Screenshot = screenshot.toString("base64");
    
          let savedLocation = path.relative(process.cwd(), outputPath);
          let resourceLink: Awaited<ReturnType<typeof registerFileResource>> | undefined;
          try {
            resourceLink = await registerFileResource({
              filePath: outputPath,
              name: filename,
              mimeType: "image/png",
              server: this.server,
            });
            if (resourceLink?.uri) {
              savedLocation = resourceLink.uri;
            }
          } catch (error) {
            console.warn("Failed to register screenshot as resource:", error);
          }
    
          // Handle base64 storage
          if (args.storeBase64 !== false) {
            this.screenshots.set(args.name || "screenshot", base64Screenshot);
          }
    
          return {
            ...createSuccessResponse(`Screenshot saved to: ${savedLocation}`),
            ...(resourceLink ? { resourceLinks: [resourceLink] } : {}),
          };
        });
      }
    
      /**
       * Get all stored screenshots
       */
      getScreenshots(): Map<string, string> {
        return this.screenshots;
      }
    }
  • The input schema definition for the playwright_screenshot tool, specifying parameters like name, selector, fullPage, etc.
    {
      name: "playwright_screenshot",
      description: "Take a screenshot of the current page or a specific element",
      inputSchema: {
        type: "object",
        properties: {
          name: { type: "string", description: "Name for the screenshot" },
          selector: { type: "string", description: "CSS selector for element to screenshot" },
          width: { type: "number", description: "Width in pixels (default: 800)" },
          height: { type: "number", description: "Height in pixels (default: 600)" },
          storeBase64: { type: "boolean", description: "Store screenshot in base64 format (default: true)" },
          fullPage: { type: "boolean", description: "Store screenshot of the entire page (default: false)" },
          savePng: { type: "boolean", description: "Save screenshot as PNG file (default: false)" },
          downloadsDir: {
            type: "string",
            description: "Custom downloads directory path (default: user's Downloads folder)",
          },
        },
        required: ["name"],
      },
    },
  • Registration of the playwright_screenshot handler in the main tool switch statement, delegating to the ScreenshotTool instance.
    case "playwright_screenshot":
      return await screenshotTool.execute(args, context);
  • Instantiation of the ScreenshotTool instance used for handling screenshot requests.
    if (!screenshotTool) screenshotTool = new ScreenshotTool(server);
  • src/tools.ts:495-495 (registration)
    Inclusion of playwright_screenshot in the BROWSER_TOOLS array, used to determine browser requirements.
    "playwright_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 states what the tool does but doesn't mention important behavioral aspects like whether it requires an active browser session, what happens if the selector isn't found, error conditions, or what the output looks like (e.g., file path, base64 string). This leaves significant gaps for a mutation tool that captures visual 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's appropriately sized and front-loaded with the core functionality, making it easy to understand at a glance.

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?

For a tool with 8 parameters, no annotations, and no output schema, the description is incomplete. It doesn't address behavioral aspects like session requirements, error handling, or output format, which are crucial for proper tool invocation. The description provides only basic purpose information without the necessary context for effective use.

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?

The input schema has 100% description coverage, so the schema already documents all 8 parameters thoroughly. The description adds no parameter-specific information beyond what's in the schema, establishing the baseline score of 3 where the schema does the heavy lifting for parameter documentation.

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 action ('Take a screenshot') and target ('current page or a specific element'), providing a specific verb+resource combination. However, it doesn't distinguish this tool from sibling tools like playwright_save_as_pdf, which also captures visual content from pages.

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 like playwright_save_as_pdf or playwright_get_visible_html. It mentions 'current page or a specific element' which gives some context but doesn't specify use cases, prerequisites, or exclusions compared to sibling tools.

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/aakashH242/mcp-playwright'

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