Skip to main content
Glama

take_screenshot

Capture browser page screenshots for automation testing and documentation using Playwright's browser control capabilities.

Instructions

Take a screenshot of the current page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
page_idNo
selectorNo

Implementation Reference

  • Handler for executing the take_screenshot tool: captures screenshot of page or element, encodes to base64, returns as ImageContent.
    elif name == "take_screenshot":
        page = get_active_page(arguments.get("page_id"))
        selector = arguments.get("selector")
        
        if selector:
            screenshot = await page.locator(selector).screenshot()
        else:
            screenshot = await page.screenshot()
        
        # Convert the bytes to base64
        base64_image = base64.b64encode(screenshot).decode('utf-8')
        
        # Return as ImageContent
        return [types.ImageContent(
            type="image",
            image=types.ImageData(
                mime_type="image/png",
                data=base64_image
            )
        )]
  • Registration of the take_screenshot tool in the list_tools() response, defining name, description, and input schema.
    types.Tool(
        name="take_screenshot",
        description="Take a screenshot of the current page",
        inputSchema={
            "type": "object",
            "properties": {
                "page_id": {"type": "string"},
                "selector": {"type": "string"},
            },
        },
    ),
  • Input schema definition for take_screenshot tool: optional page_id and selector.
    inputSchema={
        "type": "object",
        "properties": {
            "page_id": {"type": "string"},
            "selector": {"type": "string"},
        },
    },
  • Helper function used by take_screenshot (and other tools) to retrieve the active Playwright Page instance.
    def get_active_page(page_id: Optional[str] = None) -> Page:
        """Get the active page based on page_id or current default."""
        global current_page_id
        
        if page_id is None:
            page_id = current_page_id
        
        if page_id not in pages:
            raise ValueError(f"Page not found: {page_id}")
        
        return pages[page_id]

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/misanthropic-ai/playwrite-mcp'

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