@@ -1413,7 +1413,7 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
14131413 ctype = "cf_t"
14141414 else :
14151415 return
1416- if not driver .is_connected ():
1416+ if not driver .is_connected () and not __is_cdp_swap_needed ( driver ) :
14171417 driver .connect ()
14181418 time .sleep (2 )
14191419 install_pyautogui_if_missing (driver )
@@ -1425,15 +1425,18 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
14251425 )
14261426 with gui_lock : # Prevent issues with multiple processes
14271427 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
14291432 selector = "#challenge-stage"
14301433 if ctype == "g_rc" :
14311434 selector = "#recaptcha-token"
14321435 if is_in_frame and driver .is_element_present (selector ):
14331436 driver .switch_to .parent_frame ()
14341437 needs_switch = True
14351438 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 ) :
14371440 # Make sure the window is on top
14381441 page_actions .switch_to_window (
14391442 driver , driver .current_window_handle , 2 , uc_lock = False
@@ -1500,17 +1503,18 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
15001503 and frame == "iframe"
15011504 ):
15021505 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
15141518 try :
15151519 selector = "div.cf-turnstile"
15161520 if ctype == "g_rc" :
@@ -1526,11 +1530,11 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
15261530 tab_count += 1
15271531 time .sleep (0.027 )
15281532 active_element_css = js_utils .get_active_element_css (driver )
1529- print (active_element_css )
15301533 if (
15311534 active_element_css .startswith (selector )
15321535 or active_element_css .endswith (" > div" * 2 )
15331536 or (special_form and active_element_css .endswith (" div" ))
1537+ or (ctype == "g_rc" and "frame[name" in active_element_css )
15341538 ):
15351539 found_checkbox = True
15361540 sb_config ._saved_cf_tab_count = tab_count
@@ -1550,6 +1554,7 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
15501554 )
15511555 and hasattr (sb_config , "_saved_cf_tab_count" )
15521556 and sb_config ._saved_cf_tab_count
1557+ and not __is_cdp_swap_needed (driver )
15531558 ):
15541559 driver .uc_open_with_disconnect (driver .current_url , 3.8 )
15551560 with suppress (Exception ):
@@ -1764,17 +1769,27 @@ def _add_chrome_proxy_extension(
17641769 ):
17651770 # Single-threaded
17661771 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 )
17721779 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+ )
17781793 else :
17791794 # Multi-threaded
17801795 if zip_it :
@@ -1803,7 +1818,7 @@ def _add_chrome_proxy_extension(
18031818 proxy_user ,
18041819 proxy_pass ,
18051820 bypass_list ,
1806- False ,
1821+ zip_it = False ,
18071822 )
18081823 chrome_options = add_chrome_ext_dir (
18091824 chrome_options , proxy_helper .PROXY_DIR_PATH
@@ -4845,7 +4860,12 @@ def get_local_driver(
48454860 )
48464861 uc_activated = True
48474862 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+ ):
48494869 mac_certificate_error = True
48504870 else :
48514871 raise
0 commit comments