Skip to main content
Glama
jomon003

PlayMCP Browser Automation Server

by jomon003

takeScreenshot

Capture a webpage screenshot or a specific element using CSS selectors with this PlayMCP Browser Automation Server tool. Ideal for web testing and documentation.

Instructions

Take a screenshot of the page or specific element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
elementNoCSS selector for element screenshot
fullPageNoWhether to capture the full scrollable page
pathYes

Implementation Reference

  • Core implementation of the takeScreenshot tool handler. Uses Playwright to capture screenshot of the full page or specific element and saves to the given path.
    async takeScreenshot(path: string, options?: {fullPage?: boolean, element?: string}): Promise<void> { try { if (!this.isInitialized() || !this.state.page) { throw new Error('Browser not initialized'); } this.log('Taking screenshot', { path, options }); if (options?.element) { const locator = this.state.page.locator(options.element); await locator.screenshot({ path }); } else { await this.state.page.screenshot({ path, fullPage: options?.fullPage }); } this.log('Screenshot saved'); } catch (error: any) { console.error('Screenshot error:', error); throw new BrowserError('Failed to take screenshot', 'Check if the path is writable'); } }
  • Input schema definition for the takeScreenshot tool, specifying parameters: path (required string), fullPage (optional boolean), element (optional string selector).
    const TAKE_SCREENSHOT_TOOL: Tool = { name: "takeScreenshot", description: "Take a screenshot of the page or specific element", inputSchema: { type: "object", properties: { path: { type: "string" }, fullPage: { type: "boolean", description: "Whether to capture the full scrollable page" }, element: { type: "string", description: "CSS selector for element screenshot" } }, required: ["path"] } };
  • src/server.ts:548-548 (registration)
    Registration of the takeScreenshot tool in the server's tools dictionary.
    takeScreenshot: TAKE_SCREENSHOT_TOOL,
  • MCP server dispatch handler for takeScreenshot tool calls, which invokes the controller method with parsed arguments.
    case 'takeScreenshot': { if (!args.path) { return { content: [{ type: "text", text: "Path is required" }], isError: true }; } await playwrightController.takeScreenshot(args.path as string, { fullPage: args.fullPage as boolean, element: args.element as string }); return { content: [{ type: "text", text: "Screenshot taken successfully" }] }; }

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/jomon003/PlayMCP'

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