Skip to content

Commit dd5454f

Browse files
authored
Merge pull request #4397 from seleniumbase/chromium-overhaul-with-cdp-updates
Chromium overhaul with CDP Mode updates
2 parents d76b2fd + 520c0b4 commit dd5454f

10 files changed

Lines changed: 83 additions & 35 deletions

File tree

examples/cdp_mode/ReadMe.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,16 @@ sb.click_captcha()
499499
sb.gui_press_key(key)
500500
sb.gui_press_keys(keys)
501501
sb.gui_write(text)
502-
sb.gui_click_x_y(x, y, timeframe=0.25)
503-
sb.gui_click_element(selector, timeframe=0.25)
504-
sb.gui_click_with_offset(selector, x, y, timeframe=0.25, center=False)
502+
sb.gui_click_x_y(x, y, timeframe=0.27)
503+
sb.gui_click_element(selector, timeframe=0.27)
504+
sb.gui_click_with_offset(selector, x, y, timeframe=0.27, center=False)
505505
sb.gui_click_captcha()
506506
sb.gui_drag_drop_points(x1, y1, x2, y2, timeframe=0.35)
507507
sb.gui_drag_and_drop(drag_selector, drop_selector, timeframe=0.35)
508508
sb.gui_click_and_hold(selector, timeframe=0.35)
509-
sb.gui_hover_x_y(x, y)
510-
sb.gui_hover_element(selector)
509+
sb.gui_move_to_element(selector, timeframe=0.27)
510+
sb.gui_hover_x_y(x, y, timeframe=0.27)
511+
sb.gui_hover_element(selector, timeframe=0.27)
511512
sb.gui_hover_and_click(hover_selector, click_selector)
512513
sb.hover_element(selector)
513514
sb.hover_and_click(hover_selector, click_selector)
@@ -731,7 +732,7 @@ element.click()
731732
element.click_with_offset(x, y, center=False)
732733
element.flash(duration=0.5, color="EE4488")
733734
element.focus()
734-
element.gui_click(timeframe=0.25)
735+
element.gui_click(timeframe=0.27)
735736
element.highlight_overlay()
736737
element.is_in_viewport()
737738
element.mouse_click()

examples/cdp_mode/raw_priceline.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"""Priceline does a lot of A/B testing. Selectors change frequently."""
1+
"""An example of bypassing PerimeterX detection on Priceline.
2+
(PyAutoGUI is installed at runtime if it's not installed.)"""
23
from seleniumbase import SB
34

45
with SB(uc=True, test=True, locale="en", guest=True, pls="none") as sb:
@@ -8,10 +9,11 @@
89
input_selector = 'input[name="endLocation"]'
910
if not sb.is_element_present(input_selector):
1011
input_selector = "div.location-input input"
12+
sb.gui_hover_element(input_selector)
1113
sb.mouse_click(input_selector)
12-
sb.sleep(0.5)
1314
location = "Portland, OR"
1415
selection = "Oregon, United States" # (Dropdown option)
16+
sb.gui_hover_element(input_selector)
1517
sb.press_keys(input_selector, location)
1618
sb.sleep(0.5)
1719
sb.click(selection)

examples/cdp_mode/raw_southwest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""An example of bypassing bot-detection on Southwest.com.
2+
(PyAutoGUI is installed at runtime if it's not installed.)"""
13
from seleniumbase import SB
24

35
with SB(uc=True, test=True, locale="en", ad_block=True) as sb:

help_docs/cdp_mode_methods.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,16 @@ sb.click_captcha()
143143
sb.gui_press_key(key)
144144
sb.gui_press_keys(keys)
145145
sb.gui_write(text)
146-
sb.gui_click_x_y(x, y, timeframe=0.25)
147-
sb.gui_click_element(selector, timeframe=0.25)
148-
sb.gui_click_with_offset(selector, x, y, timeframe=0.25, center=False)
146+
sb.gui_click_x_y(x, y, timeframe=0.27)
147+
sb.gui_click_element(selector, timeframe=0.27)
148+
sb.gui_click_with_offset(selector, x, y, timeframe=0.27, center=False)
149149
sb.gui_click_captcha()
150150
sb.gui_drag_drop_points(x1, y1, x2, y2, timeframe=0.35)
151151
sb.gui_drag_and_drop(drag_selector, drop_selector, timeframe=0.35)
152152
sb.gui_click_and_hold(selector, timeframe=0.35)
153-
sb.gui_hover_x_y(x, y)
154-
sb.gui_hover_element(selector)
153+
sb.gui_move_to_element(selector, timeframe=0.27)
154+
sb.gui_hover_x_y(x, y, timeframe=0.27)
155+
sb.gui_hover_element(selector, timeframe=0.27)
155156
sb.gui_hover_and_click(hover_selector, click_selector)
156157
sb.hover_element(selector)
157158
sb.hover_and_click(hover_selector, click_selector)
@@ -375,7 +376,7 @@ element.click()
375376
element.click_with_offset(x, y, center=False)
376377
element.flash(duration=0.5, color="EE4488")
377378
element.focus()
378-
element.gui_click(timeframe=0.25)
379+
element.gui_click(timeframe=0.27)
379380
element.highlight_overlay()
380381
element.is_in_viewport()
381382
element.mouse_click()

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.49.13"
2+
__version__ = "4.49.14"

seleniumbase/console_scripts/sb_install.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,26 @@ def main(override=None, intel_for_uc=None, force_uc=None):
734734
platform_code = "Win"
735735
file_name = "chrome-win.zip"
736736
revision = get_chromium_latest_revision(platform_code)
737+
arg_join = " ".join(sys.argv)
738+
if "--revision" in arg_join:
739+
rev_str = None
740+
if "--revision=" in arg_join:
741+
rev_str = arg_join.split("--revision=")[1].split(" ")[0]
742+
elif "--revision " in arg_join:
743+
rev_str = arg_join.split("--revision ")[1].split(" ")[0]
744+
if rev_str:
745+
if rev_str.startswith('"') and rev_str.endswith('"'):
746+
rev_str = rev_str[1:-1]
747+
elif rev_str.startswith("'") and rev_str.endswith("'"):
748+
rev_str = rev_str[1:-1]
749+
with suppress(Exception):
750+
if int(rev_str) > 1000000:
751+
revision = rev_str
752+
else:
753+
print(
754+
"Invalid revision number! Defaulting to %s!"
755+
% revision
756+
)
737757
msg = c2 + "Chromium revision to download" + cr
738758
p_version = c3 + revision + cr
739759
log_d("\n*** %s = %s" % (msg, p_version))

seleniumbase/core/browser_launcher.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,9 @@ def uc_open_with_cdp_mode(driver, url=None, **kwargs):
851851
cdp.gui_drag_drop_points = CDPM.gui_drag_drop_points
852852
cdp.gui_drag_and_drop = CDPM.gui_drag_and_drop
853853
cdp.gui_click_and_hold = CDPM.gui_click_and_hold
854-
cdp.gui_hover_x_y = CDPM.gui_hover_x_y
854+
cdp.gui_move_to_element = CDPM.gui_move_to_element
855855
cdp.gui_hover_element = CDPM.gui_hover_element
856+
cdp.gui_hover_x_y = CDPM.gui_hover_x_y
856857
cdp.gui_hover_and_click = CDPM.gui_hover_and_click
857858
cdp.hover_element = CDPM.hover_element
858859
cdp.hover_and_click = CDPM.hover_and_click
@@ -2763,6 +2764,7 @@ def _set_chrome_options(
27632764
chrome_options.add_argument("--disable-3d-apis")
27642765
if headless or headless2 or is_using_uc(undetectable, browser_name):
27652766
chrome_options.add_argument("--disable-renderer-backgrounding")
2767+
chrome_options.add_argument("--disable-background-networking")
27662768
chrome_options.add_argument("--disable-backgrounding-occluded-windows")
27672769
chrome_options.add_argument("--disable-client-side-phishing-detection")
27682770
chrome_options.add_argument("--disable-device-discovery-notifications")
@@ -2779,7 +2781,6 @@ def _set_chrome_options(
27792781
chrome_options.add_argument("--disable-domain-reliability")
27802782
chrome_options.add_argument("--disable-breakpad")
27812783
included_disabled_features = []
2782-
included_disabled_features.append("OptimizationHints")
27832784
included_disabled_features.append("OptimizationHintsFetching")
27842785
included_disabled_features.append("Translate")
27852786
included_disabled_features.append("ComponentUpdater")
@@ -2800,14 +2801,19 @@ def _set_chrome_options(
28002801
included_disabled_features.append("UnifiedWebBluetooth")
28012802
included_disabled_features.append("WebAuthentication")
28022803
included_disabled_features.append("PasskeyAuth")
2804+
included_disabled_features.append("MediaRouter")
2805+
included_disabled_features.append("DialMediaRouteProvider")
2806+
included_disabled_features.append("WebRtcHideLocalIpsWithMdns")
2807+
if is_using_uc(undetectable, browser_name):
2808+
included_disabled_features.append("IsolateOrigins")
2809+
included_disabled_features.append("site-per-process")
28032810
for item in extra_disabled_features:
28042811
if item not in included_disabled_features:
28052812
included_disabled_features.append(item)
28062813
d_f_string = ",".join(included_disabled_features)
28072814
chrome_options.add_argument("--disable-features=%s" % d_f_string)
28082815
chrome_options.add_argument("--enable-unsafe-extension-debugging")
2809-
if proxy_string:
2810-
chrome_options.add_argument("--test-type")
2816+
chrome_options.add_argument("--test-type")
28112817
if proxy_auth or sb_config._ext_dirs:
28122818
if not is_using_uc(undetectable, browser_name):
28132819
chrome_options.add_argument("--remote-debugging-pipe")
@@ -2825,13 +2831,12 @@ def _set_chrome_options(
28252831
chrome_options.add_argument("--animation-duration-scale=0")
28262832
chrome_options.add_argument("--wm-window-animations-disabled")
28272833
chrome_options.add_argument("--enable-privacy-sandbox-ads-apis")
2834+
chrome_options.add_argument("--disable-auto-reload")
28282835
chrome_options.add_argument("--disable-background-timer-throttling")
28292836
# Prevent new tabs opened by Selenium from being blocked:
28302837
chrome_options.add_argument("--disable-popup-blocking")
28312838
# Skip remaining options that trigger anti-bot services
28322839
return chrome_options
2833-
if not proxy_string:
2834-
chrome_options.add_argument("--test-type")
28352840
chrome_options.add_argument("--log-level=3")
28362841
chrome_options.add_argument("--no-first-run")
28372842
chrome_options.add_argument("--allow-insecure-localhost")
@@ -4803,7 +4808,6 @@ def get_local_driver(
48034808
edge_options.add_argument("--disable-domain-reliability")
48044809
edge_options.add_argument("--disable-breakpad")
48054810
included_disabled_features = []
4806-
included_disabled_features.append("OptimizationHints")
48074811
included_disabled_features.append("OptimizationHintsFetching")
48084812
included_disabled_features.append("Translate")
48094813
included_disabled_features.append("ComponentUpdater")

seleniumbase/core/sb_cdp.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Add CDP methods to extend the driver"""
1+
"""The CDP Mode API (sync format), which wraps the async format."""
22
import asyncio
33
import fasteners
44
import mycdp
@@ -2035,7 +2035,7 @@ def gui_write(self, text):
20352035
self.__slow_mode_pause_if_set()
20362036
self.loop.run_until_complete(self.page.sleep(0.025))
20372037

2038-
def __gui_click_x_y(self, x, y, timeframe=0.25, uc_lock=False):
2038+
def __gui_click_x_y(self, x, y, timeframe=0.27, uc_lock=False):
20392039
self.__install_pyautogui_if_missing()
20402040
import pyautogui
20412041
pyautogui = self.__get_configured_pyautogui(pyautogui)
@@ -2065,7 +2065,7 @@ def __gui_click_x_y(self, x, y, timeframe=0.25, uc_lock=False):
20652065
print(" <DEBUG> pyautogui.click(%s, %s)" % (x, y))
20662066
pyautogui.click(x=x, y=y)
20672067

2068-
def gui_click_x_y(self, x, y, timeframe=0.25):
2068+
def gui_click_x_y(self, x, y, timeframe=0.27):
20692069
gui_lock = FileLock(constants.MultiBrowser.PYAUTOGUILOCK)
20702070
with gui_lock: # Prevent issues with multiple processes
20712071
self.__make_sure_pyautogui_lock_is_writable()
@@ -2097,7 +2097,7 @@ def gui_click_x_y(self, x, y, timeframe=0.25):
20972097
self.bring_active_window_to_front()
20982098
self.__gui_click_x_y(x, y, timeframe=timeframe, uc_lock=False)
20992099

2100-
def gui_click_element(self, selector, timeframe=0.25):
2100+
def gui_click_element(self, selector, timeframe=0.27):
21012101
self.__slow_mode_pause_if_set()
21022102
x, y = self.get_gui_element_center(selector)
21032103
self.__add_light_pause()
@@ -2106,7 +2106,7 @@ def gui_click_element(self, selector, timeframe=0.25):
21062106
self.loop.run_until_complete(self.page.wait(0.2))
21072107

21082108
def gui_click_with_offset(
2109-
self, selector, x, y, timeframe=0.25, center=False
2109+
self, selector, x, y, timeframe=0.27, center=False
21102110
):
21112111
"""Click an element at an {X,Y}-offset location.
21122112
{0,0} is the top-left corner of the element.
@@ -2577,7 +2577,7 @@ def __click_captcha(self, use_cdp=False):
25772577
return True
25782578
return False
25792579

2580-
def __gui_drag_drop(self, x1, y1, x2, y2, timeframe=0.25, uc_lock=False):
2580+
def __gui_drag_drop(self, x1, y1, x2, y2, timeframe=0.27, uc_lock=False):
25812581
self.__install_pyautogui_if_missing()
25822582
import pyautogui
25832583
pyautogui = self.__get_configured_pyautogui(pyautogui)
@@ -2672,7 +2672,11 @@ def gui_click_and_hold(self, selector, timeframe=0.35):
26722672
self.__add_light_pause()
26732673
self.gui_drag_drop_points(x, y, x, y, timeframe=timeframe)
26742674

2675-
def __gui_hover_x_y(self, x, y, timeframe=0.25, uc_lock=False):
2675+
def gui_move_to_element(self, selector, timeframe=0.27):
2676+
"""Same as gui_hover_element()"""
2677+
return self.gui_hover_element(selector, timeframe=timeframe)
2678+
2679+
def __gui_hover_x_y(self, x, y, timeframe=0.27, uc_lock=False):
26762680
self.__install_pyautogui_if_missing()
26772681
import pyautogui
26782682
pyautogui = self.__get_configured_pyautogui(pyautogui)
@@ -2697,7 +2701,7 @@ def __gui_hover_x_y(self, x, y, timeframe=0.25, uc_lock=False):
26972701
pyautogui.moveTo(x, y, timeframe, pyautogui.easeOutQuad)
26982702
time.sleep(0.056)
26992703

2700-
def gui_hover_x_y(self, x, y, timeframe=0.25):
2704+
def gui_hover_x_y(self, x, y, timeframe=0.27):
27012705
gui_lock = FileLock(constants.MultiBrowser.PYAUTOGUILOCK)
27022706
with gui_lock: # Prevent issues with multiple processes
27032707
self.__install_pyautogui_if_missing()
@@ -2748,7 +2752,12 @@ def gui_hover_x_y(self, x, y, timeframe=0.25):
27482752
self.bring_active_window_to_front()
27492753
self.__gui_hover_x_y(x, y, timeframe=timeframe, uc_lock=False)
27502754

2751-
def gui_hover_element(self, selector, timeframe=0.25):
2755+
def gui_hover_element(self, selector, timeframe=0.27):
2756+
try:
2757+
self.__verify_pyautogui_has_a_headed_browser()
2758+
except Exception:
2759+
self.hover_element(selector, timeframe=timeframe)
2760+
return
27522761
self.__slow_mode_pause_if_set()
27532762
element_rect = self.get_gui_element_rect(selector)
27542763
width = element_rect["width"]
@@ -2760,7 +2769,7 @@ def gui_hover_element(self, selector, timeframe=0.25):
27602769
self.__slow_mode_pause_if_set()
27612770
self.loop.run_until_complete(self.page.wait(0.1))
27622771

2763-
def hover_element(self, selector, timeframe=0.25):
2772+
def hover_element(self, selector, timeframe=0.27):
27642773
element = self.select(selector)
27652774
gui_lock = FileLock(constants.MultiBrowser.PYAUTOGUILOCK)
27662775
with gui_lock:

seleniumbase/fixtures/base_case.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5151,6 +5151,14 @@ def activate_cdp_mode(self, url=None, **kwargs):
51515151
self.gui_drag_and_drop = self.cdp.gui_drag_and_drop
51525152
if hasattr(self.cdp, "gui_drag_drop_points"):
51535153
self.gui_drag_drop_points = self.cdp.gui_drag_drop_points
5154+
if hasattr(self.cdp, "gui_hover_and_click"):
5155+
self.gui_hover_and_click = self.cdp.gui_hover_and_click
5156+
if hasattr(self.cdp, "gui_hover_element"):
5157+
self.gui_hover_element = self.cdp.gui_hover_element
5158+
if hasattr(self.cdp, "gui_hover_x_y"):
5159+
self.gui_hover_x_y = self.cdp.gui_hover_x_y
5160+
if hasattr(self.cdp, "gui_move_to_element"):
5161+
self.gui_move_to_element = self.cdp.gui_move_to_element
51545162
if hasattr(self.cdp, "highlight_overlay"):
51555163
self.highlight_overlay = self.cdp.highlight_overlay
51565164
if hasattr(self.cdp, "js_dumps"):

seleniumbase/undetected/cdp_driver/config.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def __init__(
250250
"--disable-ipc-flooding-protection",
251251
"--disable-background-timer-throttling",
252252
"--disable-search-engine-choice-screen",
253+
"--disable-background-networking",
253254
"--disable-backgrounding-occluded-windows",
254255
"--disable-client-side-phishing-detection",
255256
"--disable-device-discovery-notifications",
@@ -314,9 +315,9 @@ def __call__(self):
314315
"SidePanelPinning,UserAgentClientHint,PrivacySandboxSettings4,"
315316
"OptimizationHintsFetching,InterestFeedContentSuggestions,"
316317
"Bluetooth,WebBluetooth,UnifiedWebBluetooth,ComponentUpdater,"
317-
"DisableLoadExtensionCommandLineSwitch,"
318-
"OmniboxUIFeedback,OmniboxPopupShortcut,"
319-
"WebAuthentication,PasskeyAuth"
318+
"DisableLoadExtensionCommandLineSwitch,WebAuthentication,"
319+
"OmniboxUIFeedback,OmniboxPopupShortcut,PasskeyAuth,"
320+
"MediaRouter,DialMediaRouteProvider,WebRtcHideLocalIpsWithMdns"
320321
]
321322
if self.expert:
322323
args += [

0 commit comments

Comments
 (0)