Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
fix channel param to select correct browser binary
Laith Weinberger209866ed5bf1
diff --git a/browser_use/browser/watchdogs/local_browser_watchdog.py b/browser_use/browser/watchdogs/local_browser_watchdog.pyindex 296bda998..16e1f7410 100644--- a/browser_use/browser/watchdogs/local_browser_watchdog.py+++ b/browser_use/browser/watchdogs/local_browser_watchdog.py@@ -125,7 +125,7 @@ class LocalBrowserWatchdog(BaseWatchdog):else:# self.logger.debug('[LocalBrowserWatchdog] 🔍 Looking for local browser binary path...')# Try fallback paths first (system browsers preferred)- browser_path = self._find_installed_browser_path()+ browser_path = self._find_installed_browser_path(channel=profile.channel)if not browser_path:self.logger.error('[LocalBrowserWatchdog] ⚠️ No local browser binary found, installing browser using playwright subprocess...'@@ -215,14 +215,18 @@ class LocalBrowserWatchdog(BaseWatchdog):raise RuntimeError(f'Failed to launch browser after {max_retries} attempts')@staticmethod- def _find_installed_browser_path() -> str | None:+ def _find_installed_browser_path(channel: 'BrowserChannel | None' = None) -> str | None:"""Try to find browser executable from common fallback locations.+ If a channel is specified, paths for that browser are searched first.+ Falls back to all known browser paths if the channel-specific search fails.+Prioritizes:- 1. System Chrome Stable- 1. Playwright chromium- 2. Other system native browsers (Chromium -> Chrome Canary/Dev -> Brave)- 3. Playwright headless-shell fallback+ 1. Channel-specific paths (if channel is set)+ 2. System Chrome stable+ 3. Playwright chromium+ 4. Other system native browsers (Chromium -> Chrome Canary/Dev -> Brave -> Edge)+ 5. Playwright headless-shell fallbackReturns:Path to browser executable or None if not found@@ -231,60 +235,90 @@ class LocalBrowserWatchdog(BaseWatchdog):import platformfrom pathlib import Path+ from browser_use.browser.profile import BROWSERUSE_DEFAULT_CHANNEL, BrowserChannel+system = platform.system()- patterns = []# Get playwright browsers path from environment variable if setplaywright_path = os.environ.get('PLAYWRIGHT_BROWSERS_PATH')+ # Build tagged pattern lists per OS: (browser_group, path)+ # browser_group is used to match against the requested channelif system == 'Darwin': # macOSif not playwright_path:playwright_path = '~/Library/Caches/ms-playwright'- patterns = [- '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',- f'{playwright_path}/chromium-*/chrome-mac/Chromium.app/Contents/MacOS/Chromium',- '/Applications/Chromium.app/Contents/MacOS/Chromium',- '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',- '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser',- f'{playwright_path}/chromium_headless_shell-*/chrome-mac/Chromium.app/Contents/MacOS/Chromium',+ all_patterns = [+ ('chrome', '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'),+ ('chromium', f'{playwright_path}/chromium-*/chrome-mac/Chromium.app/Contents/MacOS/Chromium'),+ ('chromium', '/Applications/Chromium.app/Contents/MacOS/Chromium'),+ ('chrome-canary', '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary'),+ ('brave', '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'),+ ('msedge', '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge'),+ ('chromium', f'{playwright_path}/chromium_headless_shell-*/chrome-mac/Chromium.app/Contents/MacOS/Chromium'),]elif system == 'Linux':if not playwright_path:playwright_path = '~/.cache/ms-playwright'- patterns = [- '/usr/bin/google-chrome-stable',- '/usr/bin/google-chrome',- '/usr/local/bin/google-chrome',- f'{playwright_path}/chromium-*/chrome-linux*/chrome',- '/usr/bin/chromium',- '/usr/bin/chromium-browser',- '/usr/local/bin/chromium',- '/snap/bin/chromium',- '/usr/bin/google-chrome-beta',- '/usr/bin/google-chrome-dev',- '/usr/bin/brave-browser',- f'{playwright_path}/chromium_headless_shell-*/chrome-linux*/chrome',+ all_patterns = [+ ('chrome', '/usr/bin/google-chrome-stable'),+ ('chrome', '/usr/bin/google-chrome'),+ ('chrome', '/usr/local/bin/google-chrome'),+ ('chromium', f'{playwright_path}/chromium-*/chrome-linux*/chrome'),+ ('chromium', '/usr/bin/chromium'),+ ('chromium', '/usr/bin/chromium-browser'),+ ('chromium', '/usr/local/bin/chromium'),+ ('chromium', '/snap/bin/chromium'),+ ('chrome-beta', '/usr/bin/google-chrome-beta'),+ ('chrome-dev', '/usr/bin/google-chrome-dev'),+ ('brave', '/usr/bin/brave-browser'),+ ('msedge', '/usr/bin/microsoft-edge-stable'),+ ('msedge', '/usr/bin/microsoft-edge'),+ ('chromium', f'{playwright_path}/chromium_headless_shell-*/chrome-linux*/chrome'),]elif system == 'Windows':if not playwright_path:playwright_path = r'%LOCALAPPDATA%\ms-playwright'- patterns = [- r'C:\Program Files\Google\Chrome\Application\chrome.exe',- r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',- r'%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe',- r'%PROGRAMFILES%\Google\Chrome\Application\chrome.exe',- r'%PROGRAMFILES(X86)%\Google\Chrome\Application\chrome.exe',- f'{playwright_path}\\chromium-*\\chrome-win\\chrome.exe',- r'C:\Program Files\Chromium\Application\chrome.exe',- r'C:\Program Files (x86)\Chromium\Application\chrome.exe',- r'%LOCALAPPDATA%\Chromium\Application\chrome.exe',- r'C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe',- r'C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe',- r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe',- r'C:\Program Files\Microsoft\Edge\Application\msedge.exe',- r'%LOCALAPPDATA%\Microsoft\Edge\Application\msedge.exe',- f'{playwright_path}\\chromium_headless_shell-*\\chrome-win\\chrome.exe',+ all_patterns = [+ ('chrome', r'C:\Program Files\Google\Chrome\Application\chrome.exe'),+ ('chrome', r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'),+ ('chrome', r'%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe'),+ ('chrome', r'%PROGRAMFILES%\Google\Chrome\Application\chrome.exe'),+ ('chrome', r'%PROGRAMFILES(X86)%\Google\Chrome\Application\chrome.exe'),+ ('chromium', f'{playwright_path}\\chromium-*\\chrome-win\\chrome.exe'),+ ('chromium', r'C:\Program Files\Chromium\Application\chrome.exe'),+ ('chromium', r'C:\Program Files (x86)\Chromium\Application\chrome.exe'),+ ('chromium', r'%LOCALAPPDATA%\Chromium\Application\chrome.exe'),+ ('brave', r'C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe'),+ ('brave', r'C:\Program Files (x86)\BraveSoftware\Brave-Browser\Application\brave.exe'),+ ('msedge', r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'),+ ('msedge', r'C:\Program Files\Microsoft\Edge\Application\msedge.exe'),+ ('msedge', r'%LOCALAPPDATA%\Microsoft\Edge\Application\msedge.exe'),+ ('chromium', f'{playwright_path}\\chromium_headless_shell-*\\chrome-win\\chrome.exe'),]+ else:+ all_patterns = []++ # Map channel enum values to browser group tags+ _channel_to_group: dict[BrowserChannel, str] = {+ BrowserChannel.CHROME: 'chrome',+ BrowserChannel.CHROME_BETA: 'chrome-beta',+ BrowserChannel.CHROME_DEV: 'chrome-dev',+ BrowserChannel.CHROME_CANARY: 'chrome-canary',+ BrowserChannel.CHROMIUM: 'chromium',+ BrowserChannel.MSEDGE: 'msedge',+ BrowserChannel.MSEDGE_BETA: 'msedge',+ BrowserChannel.MSEDGE_DEV: 'msedge',+ BrowserChannel.MSEDGE_CANARY: 'msedge',+ }++ # If a non-default channel is specified, put matching patterns first, then the rest as fallback+ if channel and channel != BROWSERUSE_DEFAULT_CHANNEL and channel in _channel_to_group:+ target_group = _channel_to_group[channel]+ prioritized = [p for g, p in all_patterns if g == target_group]+ rest = [p for g, p in all_patterns if g != target_group]+ patterns = prioritized + rest+ else:+ patterns = [p for _, p in all_patterns]for pattern in patterns:# Expand user home directory