get_page_screenshots
Capture website screenshots in headless mode with options for full-page or element-specific images. Returns Base64 encoded output for easy integration and analysis.
Instructions
Capture screenshot of the current page.
Args:
full_page: Whether to capture the entire page or just the viewport
selector: Optional CSS selector to screenshot a specific element
context: Optional context object for logging (ignored)
Returns:
Base64 encoded screenshot image
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | ||
| full_page | No | ||
| selector | No |
Implementation Reference
- src/mcp_web_browser/server.py:203-243 (handler)The handler function decorated with @mcp.tool(), implementing the get_page_screenshots tool. It captures a screenshot of the current Playwright page (full page, viewport, or specific selector) and returns it as a base64-encoded string.@mcp.tool() async def get_page_screenshots( full_page: bool = False, selector: Optional[str] = None, context: Optional[Any] = None ) -> str: """ Capture screenshot of the current page. Args: full_page: Whether to capture the entire page or just the viewport selector: Optional CSS selector to screenshot a specific element context: Optional context object for logging (ignored) Returns: Base64 encoded screenshot image """ global _current_page if not _current_page: raise ValueError("No page is currently loaded. Use browse_to first.") try: if selector: element = await _current_page.query_selector(selector) if not element: raise ValueError(f"No element found with selector: {selector}") screenshot_bytes = await element.screenshot() else: screenshot_bytes = await _current_page.screenshot(full_page=full_page) # Convert to base64 for easy transmission screenshot_base64 = base64.b64encode(screenshot_bytes).decode('utf-8') print(f"Screenshot captured: {'full page' if full_page else 'viewport'}", file=sys.stderr) return screenshot_base64 except Exception as e: print(f"Error capturing screenshot: {e}", file=sys.stderr) raise ValueError(f"Error capturing screenshot: {e}")