Skip to main content
Glama

playwright_capture_screenshots

Capture screenshots across multiple browsers and viewports for visual testing and UI/UX development workflows.

Instructions

Capture screenshots across browsers and viewports

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
viewportsNo
fullPageNo

Implementation Reference

  • The main handler function that implements the playwright_capture_screenshots tool. It validates input with Zod schema, launches Chromium browser, navigates to the URL, captures screenshots for specified or default viewports, collects metadata, and returns results.
    async captureScreenshots(args: any) {
      const params = PlaywrightScreenshotSchema.parse(args);
      
      const defaultViewports = [
        { width: 1920, height: 1080, deviceScaleFactor: 1 }, // Desktop
        { width: 768, height: 1024, deviceScaleFactor: 2 },  // Tablet
        { width: 375, height: 812, deviceScaleFactor: 3 }    // Mobile
      ];
      
      const viewports = params.viewports || defaultViewports;
      const screenshots: any[] = [];
    
      try {
        const browser = await this.getBrowser('chromium');
    
        for (const viewport of viewports) {
          const context = await browser.newContext({
            viewport: {
              width: viewport.width,
              height: viewport.height
            },
            deviceScaleFactor: viewport.deviceScaleFactor || 1
          });
    
          const page = await context.newPage();
          
          try {
            await page.goto(params.url, { waitUntil: 'networkidle' });
            
            const screenshotBuffer = await page.screenshot({
              fullPage: params.fullPage
            });
    
            screenshots.push({
              viewport: `${viewport.width}x${viewport.height}`,
              deviceScaleFactor: viewport.deviceScaleFactor || 1,
              size: `${(screenshotBuffer.length / 1024).toFixed(2)}KB`,
              fullPage: params.fullPage,
              timestamp: new Date().toISOString()
            });
          } finally {
            await context.close();
          }
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                url: params.url,
                screenshots,
                message: `Captured ${screenshots.length} screenshots across different viewports`
              }, null, 2)
            }
          ]
        };
      } catch (error: any) {
        return {
          content: [
            {
              type: 'text',
              text: `Error capturing screenshots: ${error.message}`
            }
          ],
          isError: true
        };
      } finally {
        await this.closeBrowsers();
      }
    }
  • Zod schema used for input validation in the captureScreenshots handler.
    const PlaywrightScreenshotSchema = z.object({
      url: z.string().url(),
      viewports: z.array(z.object({
        width: z.number(),
        height: z.number(),
        deviceScaleFactor: z.number().optional()
      })).optional(),
      fullPage: z.boolean().default(false)
    });
  • src/index.ts:196-217 (registration)
    Tool registration in the ListToolsRequestSchema handler, defining the tool name, description, and input schema.
      name: 'playwright_capture_screenshots',
      description: 'Capture screenshots across browsers and viewports',
      inputSchema: {
        type: 'object',
        properties: {
          url: { type: 'string' },
          viewports: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                width: { type: 'number' },
                height: { type: 'number' },
                deviceScaleFactor: { type: 'number' }
              }
            }
          },
          fullPage: { type: 'boolean', default: false }
        },
        required: ['url']
      }
    },
  • src/index.ts:322-323 (registration)
    Switch case in CallToolRequestSchema handler that routes execution to the PlaywrightTools.captureScreenshots method.
    case 'playwright_capture_screenshots':
      return await this.playwrightTools.captureScreenshots(args);
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'capture' implies a read operation, it doesn't specify whether this requires network access, what happens with invalid URLs, whether it respects authentication, or what the output format looks like. The description lacks essential behavioral context for a tool that interacts with external resources.

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 extremely concise at just 5 words, with zero wasted language. It's front-loaded with the core action and scope. Every word earns its place in conveying the essential purpose.

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 3 parameters, 0% schema coverage, no annotations, and no output schema, the description is inadequate. It doesn't explain what the tool returns, how errors are handled, or provide any context about the parameters. The description leaves too many unanswered questions for effective tool selection and invocation.

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

Parameters2/5

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

With 0% schema description coverage and 3 parameters (1 required), the description provides no information about parameters. It doesn't mention the 'url' parameter at all, nor does it explain what 'viewports' or 'fullPage' mean in context. The description fails to compensate for the complete lack of schema 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 ('capture screenshots') and scope ('across browsers and viewports'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like 'playwright_test_ui' or 'storybook_test_component' that might also involve browser interaction or visual testing.

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. There's no mention of prerequisites, when-not-to-use scenarios, or comparisons with sibling tools like 'playwright_test_ui' or visual testing tools in the sibling list.

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/willem4130/ui-ux-mcp-server'

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