take_screenshot
Take a screenshot of the current page or a specific element using a CSS selector. Capture the entire scrollable page when needed.
Instructions
Take a screenshot of the current page or a specific element.
Args: full_page: Capture the entire scrollable page. selector: CSS selector of a specific element to capture.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| full_page | No | ||
| selector | No |
Implementation Reference
- The main handler function for the 'take_screenshot' MCP tool. It uses the active browser page to take a screenshot (either full-page or of a specific CSS selector element) and returns it as base64-encoded PNG.
@mcp.tool() async def take_screenshot(full_page: bool = False, selector: str | None = None) -> dict: """Take a screenshot of the current page or a specific element. Args: full_page: Capture the entire scrollable page. selector: CSS selector of a specific element to capture. """ try: page = await browser_manager.get_active_page() if selector: elem = await page.query_selector(selector) if not elem: return {"error": f"Element not found: {selector}"} data = await elem.screenshot() else: data = await page.screenshot(full_page=full_page) return {"screenshot_base64": base64.b64encode(data).decode(), "format": "png"} except Exception as e: return {"error": str(e)} - src/camoufox_reverse_mcp/tools/navigation.py:253-253 (registration)The '@mcp.tool()' decorator registers 'take_screenshot' as a tool on the FastMCP server instance.
@mcp.tool() - The function signature defines the input schema: 'full_page' (bool, default False) and 'selector' (optional str). The return type is 'dict' with either 'screenshot_base64' + 'format' or 'error'.
async def take_screenshot(full_page: bool = False, selector: str | None = None) -> dict: