browser_screenshot
Capture webpage or element screenshots and save them in desired formats or directories using Chrome automation with anti-bot detection bypass.
Instructions
Take a screenshot of the current page or a specific element
Args:
name: The name of the screenshot - required, default is "screenshot"
storeBase64: Whether to store the screenshot as a base64 string - optional, default is True
downloadsDir: The directory to save the screenshot to - optional, default is the user's Downloads directory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| downloadsDir | No | ||
| name | Yes | ||
| storeBase64 | No |
Implementation Reference
- The main handler function for the 'browser_screenshot' tool. It takes a screenshot of the current browser page, saves it to a specified directory with a timestamped filename, and optionally stores the base64 encoded image in memory under the given name. Uses undetected_chromedriver and handles browser state via shared global webdriver.@mcp.tool() async def browser_screenshot( name: str, storeBase64: bool = True, downloadsDir: str = None, ): """Take a screenshot of the current page or a specific element Args: name: The name of the screenshot - required, default is "screenshot" storeBase64: Whether to store the screenshot as a base64 string - optional, default is True downloadsDir: The directory to save the screenshot to - optional, default is the user's Downloads directory """ name = name or "screenshot" async def screenshot_handler(driver: uc.Chrome): timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H-%M-%S") filename = f"{name}-{timestamp}.png" download_dir = downloadsDir or DEFAULT_DOWNLOAD_PATH os.makedirs(download_dir, exist_ok=True) output_path = os.path.join(download_dir, filename) driver.save_screenshot(output_path) messages = [f"Screenshot saved to: {os.path.relpath(output_path, os.getcwd())}"] if storeBase64: base64 = driver.get_screenshot_as_base64() SCREENSHOTS[name] = base64 # todo: notifications/resources/list_changed messages.append(f"Screenshot also stored in memory with name: {name}") return await create_success_response(messages) return await tool.safe_execute( ToolContext(webdriver=await ensure_browser()), screenshot_handler )
- src/mcp_server_undetected_chromedriver/server.py:111-111 (registration)The @mcp.tool() decorator registers the browser_screenshot function as an MCP tool.@mcp.tool()