Skip to content
Open
29 changes: 27 additions & 2 deletions openhands-tools/openhands/tools/browser_use/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,36 @@ def _check_chromium_available() -> str | None:
if path := shutil.which(binary):
return path

# Check common Windows installation paths
windows_chrome_paths = []
env_vars = [
("PROGRAMFILES", "C:\\Program Files"),
("PROGRAMFILES(X86)", "C:\\Program Files (x86)"),
("LOCALAPPDATA", ""),
]
windows_browsers = [
("Google", "Chrome", "Application", "chrome.exe"),
("Microsoft", "Edge", "Application", "msedge.exe"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, why do we need browsers on Windows, doesn't the browser tool work with playwright?

Copy link
Contributor Author

@SmartManoj SmartManoj Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use existing browsers instead of installing browsers using playwright (uvx playwright install chromium)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def _check_chromium_available() -> str | None:
"""Check if a Chromium/Chrome binary is available in PATH."""
for binary in ("chromium", "chromium-browser", "google-chrome", "chrome"):
if path := shutil.which(binary):
return path
# Check Playwright-installed Chromium
playwright_cache_candidates = [
Path.home() / ".cache" / "ms-playwright",
Path.home() / "Library" / "Caches" / "ms-playwright",
]
for playwright_cache in playwright_cache_candidates:
if playwright_cache.exists():
chromium_dirs = list(playwright_cache.glob("chromium-*"))
for chromium_dir in chromium_dirs:
# Check platform-specific paths
possible_paths = [
chromium_dir / "chrome-linux" / "chrome", # Linux
chromium_dir
/ "chrome-mac"
/ "Chromium.app"
/ "Contents"
/ "MacOS"
/ "Chromium", # macOS
chromium_dir / "chrome-win" / "chrome.exe", # Windows
]
for p in possible_paths:
if p.exists():
return str(p)
return None

Line 34, in WIndows, browser is not in Path by default,

image

Without checking for existing browser, it will work if it is installed from Playwright.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thank you.

Tiny nit: could we call them windows_browsers?

Is LOCALAPPDATA a common env var used on Windows? Is it set by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is LOCALAPPDATA a common env var used on Windows? Is it set by default?

Yes. Source: https://devblogs.microsoft.com/oldnewthing/20231212-00/?p=109137

]

for env_var, default in env_vars:
for vendor, browser, app_dir, executable in windows_browsers:
base_path = Path(os.environ.get(env_var, default))
if base_path:
windows_chrome_paths.append(
base_path / vendor / browser / app_dir / executable
)
for chrome_path in windows_chrome_paths:
if chrome_path.exists():
return str(chrome_path)

# Check Playwright-installed Chromium
playwright_cache_candidates = [
Path.home() / ".cache" / "ms-playwright",
Path.home() / "Library" / "Caches" / "ms-playwright",
Path.home() / ".cache" / "ms-playwright", # Linux
Path.home() / "Library" / "Caches" / "ms-playwright", # macOS
Path(os.environ.get("LOCALAPPDATA", "")) / "ms-playwright", # Windows
]

for playwright_cache in playwright_cache_candidates:
if playwright_cache.exists():
chromium_dirs = list(playwright_cache.glob("chromium-*"))
Expand Down
Loading