diff --git a/seleniumbase/__version__.py b/seleniumbase/__version__.py index a52a178673e..c932c3b534e 100755 --- a/seleniumbase/__version__.py +++ b/seleniumbase/__version__.py @@ -1,2 +1,2 @@ # seleniumbase package -__version__ = "4.34.9" +__version__ = "4.34.10" diff --git a/seleniumbase/core/detect_b_ver.py b/seleniumbase/core/detect_b_ver.py index a0433a47303..e8dd71d0505 100644 --- a/seleniumbase/core/detect_b_ver.py +++ b/seleniumbase/core/detect_b_ver.py @@ -96,14 +96,9 @@ def linux_browser_apps_to_cmd(*apps): ) -def chrome_on_linux_path(prefer_chromium=False): +def chrome_on_linux_path(chromium_ok=False): if os_name() != OSType.LINUX: return "" - if prefer_chromium: - paths = ["/bin/chromium", "/bin/chromium-browser"] - for path in paths: - if os.path.exists(path) and os.access(path, os.X_OK): - return path paths = ["/bin/google-chrome", "/bin/google-chrome-stable"] for path in paths: if os.path.exists(path) and os.access(path, os.X_OK): @@ -112,17 +107,22 @@ def chrome_on_linux_path(prefer_chromium=False): binaries = [] binaries.append("google-chrome") binaries.append("google-chrome-stable") - binaries.append("chrome") - binaries.append("chromium") - binaries.append("chromium-browser") binaries.append("google-chrome-beta") binaries.append("google-chrome-dev") binaries.append("google-chrome-unstable") + binaries.append("chrome") + binaries.append("chromium") + binaries.append("chromium-browser") for binary in binaries: for path in paths: full_path = os.path.join(path, binary) if os.path.exists(full_path) and os.access(full_path, os.X_OK): return full_path + if chromium_ok: + paths = ["/bin/chromium", "/bin/chromium-browser"] + for path in paths: + if os.path.exists(path) and os.access(path, os.X_OK): + return path return "/usr/bin/google-chrome" @@ -209,12 +209,11 @@ def windows_browser_apps_to_cmd(*apps): return '%s -NoProfile "%s"' % (powershell, script) -def get_binary_location(browser_type, prefer_chromium=False): - """Return the full path of the browser binary. - If going for better results in UC Mode, use: prefer_chromium=True""" +def get_binary_location(browser_type, chromium_ok=False): + """Return the full path of the browser binary.""" cmd_mapping = { ChromeType.GOOGLE: { - OSType.LINUX: chrome_on_linux_path(prefer_chromium), + OSType.LINUX: chrome_on_linux_path(chromium_ok), OSType.MAC: r"/Applications/Google Chrome.app" r"/Contents/MacOS/Google Chrome", OSType.WIN: chrome_on_windows_path(), diff --git a/seleniumbase/undetected/__init__.py b/seleniumbase/undetected/__init__.py index 1649f1f34d7..83cff37b382 100644 --- a/seleniumbase/undetected/__init__.py +++ b/seleniumbase/undetected/__init__.py @@ -586,14 +586,14 @@ def find_chrome_executable(): if IS_POSIX: for item in os.environ.get("PATH").split(os.pathsep): for subitem in ( - "chromium", "google-chrome", - "chromium-browser", - "chrome", "google-chrome-stable", "google-chrome-beta", "google-chrome-dev", "google-chrome-unstable", + "chrome", + "chromium", + "chromium-browser", ): candidates.add(os.sep.join((item, subitem))) if "darwin" in sys.platform: diff --git a/seleniumbase/undetected/cdp_driver/browser.py b/seleniumbase/undetected/cdp_driver/browser.py index 83ed2c133a9..3ed79233cdc 100644 --- a/seleniumbase/undetected/cdp_driver/browser.py +++ b/seleniumbase/undetected/cdp_driver/browser.py @@ -565,10 +565,11 @@ def stop(self): # asyncio.get_running_loop().create_task( # self.connection.send(cdp.browser.close()) # ) - asyncio.get_event_loop().create_task(self.connection.aclose()) - logger.debug( - "Closed the connection using get_event_loop().create_task()" - ) + if self.connection: + asyncio.get_event_loop().create_task(self.connection.aclose()) + logger.debug( + "Closed connection using get_event_loop().create_task()" + ) except RuntimeError: if self.connection: try: diff --git a/seleniumbase/undetected/cdp_driver/cdp_util.py b/seleniumbase/undetected/cdp_driver/cdp_util.py index 7de1dbe1c04..1f602a14af3 100644 --- a/seleniumbase/undetected/cdp_driver/cdp_util.py +++ b/seleniumbase/undetected/cdp_driver/cdp_util.py @@ -10,6 +10,7 @@ from contextlib import suppress from seleniumbase import config as sb_config from seleniumbase.config import settings +from seleniumbase.core import detect_b_ver from seleniumbase.fixtures import constants from seleniumbase.fixtures import shared_utils from typing import Optional, List, Union, Callable @@ -226,6 +227,10 @@ async def start_async(*args, **kwargs) -> Browser: binary_location = None if "browser_executable_path" in kwargs: binary_location = kwargs["browser_executable_path"] + else: + binary_location = detect_b_ver.get_binary_location("google-chrome") + if binary_location and not os.path.exists(binary_location): + binary_location = None if ( shared_utils.is_chrome_130_or_newer(binary_location) and "user_data_dir" in kwargs @@ -261,6 +266,10 @@ def start_sync(*args, **kwargs) -> Browser: binary_location = None if "browser_executable_path" in kwargs: binary_location = kwargs["browser_executable_path"] + else: + binary_location = detect_b_ver.get_binary_location("google-chrome") + if binary_location and not os.path.exists(binary_location): + binary_location = None if ( shared_utils.is_chrome_130_or_newer(binary_location) and "user_data_dir" in kwargs