Skip to main content
Glama

browser_take_screenshot

Capture screenshots of web pages or specific elements using Playwright MCP Server. Automate visual documentation, debugging, or content extraction tasks with ease.

Instructions

Take a screenshot of the current page or a specific element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fullPageNo
selectorNo

Implementation Reference

  • The core handler function that implements the browser_take_screenshot tool. It validates input, ensures Playwright connection, captures screenshot of the full page or specified element, encodes it to base64, and returns it in the response.
    async (params: any) => { try { const input = z.object({ fullPage: z.boolean().optional().default(false), selector: z.string().optional() }).parse(params); await this.playwright.ensureConnected(); const page = this.playwright.getPage(); let screenshot: Buffer; if (input.selector) { const element = await page.locator(input.selector); screenshot = await element.screenshot(); } else { screenshot = await page.screenshot({ fullPage: input.fullPage }); } return { content: [{ type: 'text', text: `Screenshot taken (${screenshot.length} bytes), base64: ${screenshot.toString('base64')}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Screenshot failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
  • src/server.ts:63-72 (registration)
    Registers the browser_take_screenshot tool with the MCP server, providing title, description, and inline input schema.
    this.server.registerTool( 'browser_take_screenshot', { title: 'Take Screenshot', description: 'Take a screenshot of the current page or a specific element', inputSchema: { fullPage: z.boolean().optional().default(false), selector: z.string().optional() } },
  • Zod input schema definition for the browser_take_screenshot tool, defining optional fullPage and selector parameters.
    export const BrowserTakeScreenshotInputSchema = z.object({ fullPage: z.boolean().optional().default(false), selector: z.string().optional() });
  • TypeScript type inferred from the BrowserTakeScreenshotInputSchema for type safety.
    export type BrowserTakeScreenshotInput = z.infer<typeof BrowserTakeScreenshotInputSchema>;

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

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