Skip to content

CDP Mode: Patch 41 #3593

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 5 commits into from
Mar 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
11 changes: 11 additions & 0 deletions examples/cdp_mode/raw_consecutive_c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# An example of bypassing 2 consecutive CF CAPTCHAs"""
from seleniumbase import SB

with SB(uc=True, test=True) as sb:
url = "https://sms-man.com/login"
sb.activate_cdp_mode(url)
sb.sleep(2)
sb.uc_gui_click_captcha()
sb.sleep(2)
sb.uc_gui_click_captcha()
sb.sleep(2)
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ attrs>=25.1.0
certifi>=2025.1.31
exceptiongroup>=1.2.2
websockets~=13.1;python_version<"3.9"
websockets>=15.0;python_version>="3.9"
websockets>=15.0.1;python_version>="3.9"
filelock~=3.16.1;python_version<"3.9"
filelock>=3.17.0;python_version>="3.9"
fasteners>=0.19
Expand All @@ -18,7 +18,7 @@ typing-extensions>=4.12.2
sbvirtualdisplay>=1.4.0
MarkupSafe==2.1.5;python_version<"3.9"
MarkupSafe>=3.0.2;python_version>="3.9"
Jinja2>=3.1.5
Jinja2>=3.1.6
six>=1.17.0
parse>=1.20.2
parse-type>=0.6.4
Expand Down
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.35.4"
__version__ = "4.35.5"
39 changes: 37 additions & 2 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,13 @@ def _uc_gui_click_captcha(
and driver.is_element_present("form div:not(:has(*))")
):
frame = "form div:not(:has(*))"
elif (
driver.is_element_present('[src*="/turnstile/"]')
and driver.is_element_present(
"body > div#check > div:not([class])"
)
):
frame = "body > div#check > div:not([class])"
elif driver.is_element_present(".cf-turnstile-wrapper"):
frame = ".cf-turnstile-wrapper"
elif driver.is_element_present(
Expand Down Expand Up @@ -1319,15 +1326,36 @@ def _uc_gui_click_captcha(
driver.cdp.evaluate(script)
else:
driver.execute_script(script)
elif (
driver.is_element_present("form")
and (
driver.is_element_present('form div[style*="center"]')
or driver.is_element_present('form div[style*="right"]')
)
):
script = (
"""var $elements = document.querySelectorAll(
'form[style], form div[style]');
var index = 0, length = $elements.length;
for(; index < length; index++){
the_style = $elements[index].getAttribute('style');
new_style = the_style.replaceAll('center', 'left');
new_style = new_style.replaceAll('right', 'left');
$elements[index].setAttribute('style', new_style);}"""
)
if __is_cdp_swap_needed(driver):
driver.cdp.evaluate(script)
else:
driver.execute_script(script)
elif (
driver.is_element_present("form")
and driver.is_element_present(
"form.turnstile #turnstile-widget > div:not([class])"
'form [id*="turnstile"] > div:not([class])'
)
):
script = (
"""var $elements = document.querySelectorAll(
'form.turnstile #turnstile-widget');
'form [id*="turnstile"]');
var index = 0, length = $elements.length;
for(; index < length; index++){
$elements[index].setAttribute('align', 'left');}"""
Expand Down Expand Up @@ -1577,6 +1605,13 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
):
frame = "form div:not(:has(*))"
tab_up_first = True
elif (
driver.is_element_present('[src*="/turnstile/"]')
and driver.is_element_present(
"body > div#check > div:not([class])"
)
):
frame = "body > div#check > div:not([class])"
else:
return
else:
Expand Down
17 changes: 17 additions & 0 deletions seleniumbase/plugins/driver_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,23 @@ def Driver(
swiftshader = False
if locale is not None and locale_code is None:
locale_code = locale
if locale_code is None:
if '--locale="' in arg_join:
locale_code = (
arg_join.split('--locale="')[1].split('"')[0]
)
elif '--locale=' in arg_join:
locale_code = (
arg_join.split('--locale=')[1].split(' ')[0]
)
elif '--locale-code="' in arg_join:
locale_code = (
arg_join.split('--locale-code="')[1].split('"')[0]
)
elif '--locale-code=' in arg_join:
locale_code = (
arg_join.split('--locale-code=')[1].split(' ')[0]
)
if ad_block is not None and ad_block_on is None:
ad_block_on = ad_block
if ad_block_on is None:
Expand Down
17 changes: 17 additions & 0 deletions seleniumbase/plugins/sb_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,23 @@ def SB(
swiftshader = False
if locale is not None and locale_code is None:
locale_code = locale
if locale_code is None:
if '--locale="' in arg_join:
locale_code = (
arg_join.split('--locale="')[1].split('"')[0]
)
elif '--locale=' in arg_join:
locale_code = (
arg_join.split('--locale=')[1].split(' ')[0]
)
elif '--locale-code="' in arg_join:
locale_code = (
arg_join.split('--locale-code="')[1].split('"')[0]
)
elif '--locale-code=' in arg_join:
locale_code = (
arg_join.split('--locale-code=')[1].split(' ')[0]
)
if ad_block is not None and ad_block_on is None:
ad_block_on = ad_block
if ad_block_on is None:
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"certifi>=2025.1.31",
"exceptiongroup>=1.2.2",
'websockets~=13.1;python_version<"3.9"',
'websockets>=15.0;python_version>="3.9"',
'websockets>=15.0.1;python_version>="3.9"',
'filelock~=3.16.1;python_version<"3.9"',
'filelock>=3.17.0;python_version>="3.9"',
'fasteners>=0.19',
Expand All @@ -167,7 +167,7 @@
"sbvirtualdisplay>=1.4.0",
'MarkupSafe==2.1.5;python_version<"3.9"',
'MarkupSafe>=3.0.2;python_version>="3.9"',
"Jinja2>=3.1.5",
"Jinja2>=3.1.6",
"six>=1.17.0",
'parse>=1.20.2',
'parse-type>=0.6.4',
Expand Down