Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d3aab4a

Browse files
authored
Merge pull request #3490 from seleniumbase/cdp-mode-patch-31
CDP Mode - Patch 31
2 parents 82de835 + e85d7f0 commit d3aab4a

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

‎seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.34.9"
2+
__version__ = "4.34.10"

‎seleniumbase/core/detect_b_ver.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,9 @@ def linux_browser_apps_to_cmd(*apps):
9696
)
9797

9898

99-
def chrome_on_linux_path(prefer_chromium=False):
99+
def chrome_on_linux_path(chromium_ok=False):
100100
if os_name() != OSType.LINUX:
101101
return ""
102-
if prefer_chromium:
103-
paths = ["/bin/chromium", "/bin/chromium-browser"]
104-
for path in paths:
105-
if os.path.exists(path) and os.access(path, os.X_OK):
106-
return path
107102
paths = ["/bin/google-chrome", "/bin/google-chrome-stable"]
108103
for path in paths:
109104
if os.path.exists(path) and os.access(path, os.X_OK):
@@ -112,17 +107,22 @@ def chrome_on_linux_path(prefer_chromium=False):
112107
binaries = []
113108
binaries.append("google-chrome")
114109
binaries.append("google-chrome-stable")
115-
binaries.append("chrome")
116-
binaries.append("chromium")
117-
binaries.append("chromium-browser")
118110
binaries.append("google-chrome-beta")
119111
binaries.append("google-chrome-dev")
120112
binaries.append("google-chrome-unstable")
113+
binaries.append("chrome")
114+
binaries.append("chromium")
115+
binaries.append("chromium-browser")
121116
for binary in binaries:
122117
for path in paths:
123118
full_path = os.path.join(path, binary)
124119
if os.path.exists(full_path) and os.access(full_path, os.X_OK):
125120
return full_path
121+
if chromium_ok:
122+
paths = ["/bin/chromium", "/bin/chromium-browser"]
123+
for path in paths:
124+
if os.path.exists(path) and os.access(path, os.X_OK):
125+
return path
126126
return "/usr/bin/google-chrome"
127127

128128

@@ -209,12 +209,11 @@ def windows_browser_apps_to_cmd(*apps):
209209
return '%s -NoProfile "%s"' % (powershell, script)
210210

211211

212-
def get_binary_location(browser_type, prefer_chromium=False):
213-
"""Return the full path of the browser binary.
214-
If going for better results in UC Mode, use: prefer_chromium=True"""
212+
def get_binary_location(browser_type, chromium_ok=False):
213+
"""Return the full path of the browser binary."""
215214
cmd_mapping = {
216215
ChromeType.GOOGLE: {
217-
OSType.LINUX: chrome_on_linux_path(prefer_chromium),
216+
OSType.LINUX: chrome_on_linux_path(chromium_ok),
218217
OSType.MAC: r"/Applications/Google Chrome.app"
219218
r"/Contents/MacOS/Google Chrome",
220219
OSType.WIN: chrome_on_windows_path(),

‎seleniumbase/undetected/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -586,14 +586,14 @@ def find_chrome_executable():
586586
if IS_POSIX:
587587
for item in os.environ.get("PATH").split(os.pathsep):
588588
for subitem in (
589-
"chromium",
590589
"google-chrome",
591-
"chromium-browser",
592-
"chrome",
593590
"google-chrome-stable",
594591
"google-chrome-beta",
595592
"google-chrome-dev",
596593
"google-chrome-unstable",
594+
"chrome",
595+
"chromium",
596+
"chromium-browser",
597597
):
598598
candidates.add(os.sep.join((item, subitem)))
599599
if "darwin" in sys.platform:

‎seleniumbase/undetected/cdp_driver/browser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,11 @@ def stop(self):
565565
# asyncio.get_running_loop().create_task(
566566
# self.connection.send(cdp.browser.close())
567567
# )
568-
asyncio.get_event_loop().create_task(self.connection.aclose())
569-
logger.debug(
570-
"Closed the connection using get_event_loop().create_task()"
571-
)
568+
if self.connection:
569+
asyncio.get_event_loop().create_task(self.connection.aclose())
570+
logger.debug(
571+
"Closed connection using get_event_loop().create_task()"
572+
)
572573
except RuntimeError:
573574
if self.connection:
574575
try:

‎seleniumbase/undetected/cdp_driver/cdp_util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from contextlib import suppress
1111
from seleniumbase import config as sb_config
1212
from seleniumbase.config import settings
13+
from seleniumbase.core import detect_b_ver
1314
from seleniumbase.fixtures import constants
1415
from seleniumbase.fixtures import shared_utils
1516
from typing import Optional, List, Union, Callable
@@ -226,6 +227,10 @@ async def start_async(*args, **kwargs) -> Browser:
226227
binary_location = None
227228
if "browser_executable_path" in kwargs:
228229
binary_location = kwargs["browser_executable_path"]
230+
else:
231+
binary_location = detect_b_ver.get_binary_location("google-chrome")
232+
if binary_location and not os.path.exists(binary_location):
233+
binary_location = None
229234
if (
230235
shared_utils.is_chrome_130_or_newer(binary_location)
231236
and "user_data_dir" in kwargs
@@ -261,6 +266,10 @@ def start_sync(*args, **kwargs) -> Browser:
261266
binary_location = None
262267
if "browser_executable_path" in kwargs:
263268
binary_location = kwargs["browser_executable_path"]
269+
else:
270+
binary_location = detect_b_ver.get_binary_location("google-chrome")
271+
if binary_location and not os.path.exists(binary_location):
272+
binary_location = None
264273
if (
265274
shared_utils.is_chrome_130_or_newer(binary_location)
266275
and "user_data_dir" in kwargs

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /