From 002fb405639483c454f5a582a2fe7b4f9ea9f1f2 Mon Sep 17 00:00:00 2001 From: openhands Date: Thu, 4 Dec 2025 22:56:43 +0000 Subject: [PATCH] Add --check-browser flag for browser functionality testing - Add command line flag --check-browser to test browser functionality - Tests if browser can render about:blank page - Exits with code 0 on success, 1 on failure - Useful for deployment verification and health monitoring Co-authored-by: openhands --- .../openhands/agent_server/__main__.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/openhands-agent-server/openhands/agent_server/__main__.py b/openhands-agent-server/openhands/agent_server/__main__.py index c65a935a4b..9a101f331c 100644 --- a/openhands-agent-server/openhands/agent_server/__main__.py +++ b/openhands-agent-server/openhands/agent_server/__main__.py @@ -1,4 +1,5 @@ import argparse +import sys import uvicorn @@ -6,6 +7,41 @@ from openhands.sdk.logger import DEBUG +def check_browser(): + """Check if browser functionality can render about:blank.""" + try: + # Register tools to ensure browser tools are available + from openhands.tools.preset.default import register_default_tools + + register_default_tools(enable_browser=True) + + # Import browser components + from openhands.tools.browser_use.definition import BrowserNavigateAction + from openhands.tools.browser_use.impl import BrowserToolExecutor + + # Create executor + executor = BrowserToolExecutor(headless=True, session_timeout_minutes=1) + + # Try to navigate to about:blank + action = BrowserNavigateAction(url="about:blank") + result = executor(action) + + # Clean up + executor.close() + + # Check if the operation was successful + if result.is_error: + print(f"Browser check failed: {result.content}") + return False + + print("Browser check passed: Successfully rendered about:blank") + return True + + except Exception as e: + print(f"Browser check failed: {e}") + return False + + def main(): parser = argparse.ArgumentParser(description="OpenHands Agent Server App") parser.add_argument( @@ -21,9 +57,21 @@ def main(): action="store_true", help="Enable auto-reload (disabled by default)", ) + parser.add_argument( + "--check-browser", + action="store_true", + help="Check if browser functionality works and exit", + ) args = parser.parse_args() + # Handle browser check + if args.check_browser: + if check_browser(): + sys.exit(0) + else: + sys.exit(1) + print(f"🙌 Starting OpenHands Agent Server on {args.host}:{args.port}") print(f"📖 API docs will be available at http://{args.host}:{args.port}/docs") print(f"🔄 Auto-reload: {'enabled' if args.reload else 'disabled'}")