@@ -1413,7 +1413,7 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
1413
1413
ctype = "cf_t"
1414
1414
else :
1415
1415
return
1416
- if not driver .is_connected ():
1416
+ if not driver .is_connected () and not __is_cdp_swap_needed ( driver ) :
1417
1417
driver .connect ()
1418
1418
time .sleep (2 )
1419
1419
install_pyautogui_if_missing (driver )
@@ -1425,15 +1425,18 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
1425
1425
)
1426
1426
with gui_lock : # Prevent issues with multiple processes
1427
1427
needs_switch = False
1428
- is_in_frame = js_utils .is_in_frame (driver )
1428
+ if not __is_cdp_swap_needed (driver ):
1429
+ is_in_frame = js_utils .is_in_frame (driver )
1430
+ else :
1431
+ is_in_frame = False
1429
1432
selector = "#challenge-stage"
1430
1433
if ctype == "g_rc" :
1431
1434
selector = "#recaptcha-token"
1432
1435
if is_in_frame and driver .is_element_present (selector ):
1433
1436
driver .switch_to .parent_frame ()
1434
1437
needs_switch = True
1435
1438
is_in_frame = js_utils .is_in_frame (driver )
1436
- if not is_in_frame :
1439
+ if not is_in_frame and not __is_cdp_swap_needed ( driver ) :
1437
1440
# Make sure the window is on top
1438
1441
page_actions .switch_to_window (
1439
1442
driver , driver .current_window_handle , 2 , uc_lock = False
@@ -1500,17 +1503,18 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
1500
1503
and frame == "iframe"
1501
1504
):
1502
1505
frame = 'iframe[title="reCAPTCHA"]'
1503
- if not is_in_frame or needs_switch :
1504
- # Currently not in frame (or nested frame outside CF one)
1505
- try :
1506
- if visible_iframe or ctype == "g_rc" :
1507
- driver .switch_to_frame (frame )
1508
- except Exception :
1509
- if visible_iframe or ctype == "g_rc" :
1510
- if driver .is_element_present ("iframe" ):
1511
- driver .switch_to_frame ("iframe" )
1512
- else :
1513
- return
1506
+ if not __is_cdp_swap_needed (driver ):
1507
+ if not is_in_frame or needs_switch :
1508
+ # Currently not in frame (or nested frame outside CF one)
1509
+ try :
1510
+ if visible_iframe or ctype == "g_rc" :
1511
+ driver .switch_to_frame (frame )
1512
+ except Exception :
1513
+ if visible_iframe or ctype == "g_rc" :
1514
+ if driver .is_element_present ("iframe" ):
1515
+ driver .switch_to_frame ("iframe" )
1516
+ else :
1517
+ return
1514
1518
try :
1515
1519
selector = "div.cf-turnstile"
1516
1520
if ctype == "g_rc" :
@@ -1526,11 +1530,11 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
1526
1530
tab_count += 1
1527
1531
time .sleep (0.027 )
1528
1532
active_element_css = js_utils .get_active_element_css (driver )
1529
- print (active_element_css )
1530
1533
if (
1531
1534
active_element_css .startswith (selector )
1532
1535
or active_element_css .endswith (" > div" * 2 )
1533
1536
or (special_form and active_element_css .endswith (" div" ))
1537
+ or (ctype == "g_rc" and "frame[name" in active_element_css )
1534
1538
):
1535
1539
found_checkbox = True
1536
1540
sb_config ._saved_cf_tab_count = tab_count
@@ -1550,6 +1554,7 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
1550
1554
)
1551
1555
and hasattr (sb_config , "_saved_cf_tab_count" )
1552
1556
and sb_config ._saved_cf_tab_count
1557
+ and not __is_cdp_swap_needed (driver )
1553
1558
):
1554
1559
driver .uc_open_with_disconnect (driver .current_url , 3.8 )
1555
1560
with suppress (Exception ):
@@ -1764,17 +1769,27 @@ def _add_chrome_proxy_extension(
1764
1769
):
1765
1770
# Single-threaded
1766
1771
if zip_it :
1767
- proxy_helper .create_proxy_ext (
1768
- proxy_string , proxy_user , proxy_pass , bypass_list
1769
- )
1770
- proxy_zip = proxy_helper .PROXY_ZIP_PATH
1771
- chrome_options .add_extension (proxy_zip )
1772
+ proxy_zip_lock = fasteners .InterProcessLock (PROXY_ZIP_LOCK )
1773
+ with proxy_zip_lock :
1774
+ proxy_helper .create_proxy_ext (
1775
+ proxy_string , proxy_user , proxy_pass , bypass_list
1776
+ )
1777
+ proxy_zip = proxy_helper .PROXY_ZIP_PATH
1778
+ chrome_options .add_extension (proxy_zip )
1772
1779
else :
1773
- proxy_helper .create_proxy_ext (
1774
- proxy_string , proxy_user , proxy_pass , bypass_list , zip_it = False
1775
- )
1776
- proxy_dir_path = proxy_helper .PROXY_DIR_PATH
1777
- chrome_options = add_chrome_ext_dir (chrome_options , proxy_dir_path )
1780
+ proxy_dir_lock = fasteners .InterProcessLock (PROXY_DIR_LOCK )
1781
+ with proxy_dir_lock :
1782
+ proxy_helper .create_proxy_ext (
1783
+ proxy_string ,
1784
+ proxy_user ,
1785
+ proxy_pass ,
1786
+ bypass_list ,
1787
+ zip_it = False ,
1788
+ )
1789
+ proxy_dir_path = proxy_helper .PROXY_DIR_PATH
1790
+ chrome_options = add_chrome_ext_dir (
1791
+ chrome_options , proxy_dir_path
1792
+ )
1778
1793
else :
1779
1794
# Multi-threaded
1780
1795
if zip_it :
@@ -1803,7 +1818,7 @@ def _add_chrome_proxy_extension(
1803
1818
proxy_user ,
1804
1819
proxy_pass ,
1805
1820
bypass_list ,
1806
- False ,
1821
+ zip_it = False ,
1807
1822
)
1808
1823
chrome_options = add_chrome_ext_dir (
1809
1824
chrome_options , proxy_helper .PROXY_DIR_PATH
@@ -4845,7 +4860,12 @@ def get_local_driver(
4845
4860
)
4846
4861
uc_activated = True
4847
4862
except URLError as e :
4848
- if cert in e .args [0 ] and IS_MAC :
4863
+ if (
4864
+ IS_MAC
4865
+ and hasattr (e , "args" )
4866
+ and isinstance (e .args , (list , tuple ))
4867
+ and cert in e .args [0 ]
4868
+ ):
4849
4869
mac_certificate_error = True
4850
4870
else :
4851
4871
raise
0 commit comments