Skip to content

CDP Mode - Patch 31 #3490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.34.9"
__version__ = "4.34.10"
25 changes: 12 additions & 13 deletions seleniumbase/core/detect_b_ver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"


Expand Down Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions seleniumbase/undetected/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions seleniumbase/undetected/cdp_driver/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions seleniumbase/undetected/cdp_driver/cdp_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down