@@ -2523,7 +2523,7 @@ def get_local_driver(
2523
2523
chrome_options .add_argument ("--headless=new" )
2524
2524
disable_build_check = False
2525
2525
uc_driver_version = None
2526
- if IS_ARM_MAC :
2526
+ if is_using_uc ( undetectable , browser_name ) :
2527
2527
uc_driver_version = get_uc_driver_version ()
2528
2528
if (
2529
2529
LOCAL_CHROMEDRIVER
@@ -2609,22 +2609,39 @@ def get_local_driver(
2609
2609
)
2610
2610
)
2611
2611
):
2612
- sb_install .main (
2613
- override = "chromedriver latest"
2614
- )
2612
+ sb_install .main (override = "chromedriver latest" )
2615
2613
sys .argv = sys_args # Put back the original sys args
2616
2614
else :
2615
+ # (Multithreaded)
2617
2616
chromedriver_fixing_lock = fasteners .InterProcessLock (
2618
2617
constants .MultiBrowser .DRIVER_FIXING_LOCK
2619
2618
)
2620
2619
with chromedriver_fixing_lock :
2621
- if not chromedriver_on_path ():
2622
- sys_args = sys . argv # Save a copy of sys args
2620
+ msg = "chromedriver update needed. Getting it now:"
2621
+ if not path_chromedriver :
2623
2622
msg = "chromedriver not found. Getting it now:"
2623
+ intel_for_uc = False
2624
+ if (
2625
+ IS_ARM_MAC
2626
+ and is_using_uc (undetectable , browser_name )
2627
+ ):
2628
+ intel_for_uc = True # Use Intel driver for UC Mode
2629
+ if (
2630
+ (
2631
+ not is_using_uc (undetectable , browser_name )
2632
+ and not os .path .exists (LOCAL_CHROMEDRIVER )
2633
+ )
2634
+ or (
2635
+ is_using_uc (undetectable , browser_name )
2636
+ and not os .path .exists (LOCAL_UC_DRIVER )
2637
+ )
2638
+ ):
2624
2639
print ("\n Warning: %s" % msg )
2640
+ sys_args = sys .argv # Save a copy of sys args
2625
2641
try :
2626
2642
sb_install .main (
2627
- override = "chromedriver %s" % use_version
2643
+ override = "chromedriver %s" % use_version ,
2644
+ intel_for_uc = intel_for_uc ,
2628
2645
)
2629
2646
except Exception :
2630
2647
d_latest = get_latest_chromedriver_version ()
@@ -2651,7 +2668,8 @@ def get_local_driver(
2651
2668
sb_install .main (
2652
2669
override = "chromedriver latest"
2653
2670
)
2654
- sys .argv = sys_args # Put back original sys args
2671
+ finally :
2672
+ sys .argv = sys_args # Put back original args
2655
2673
service_args = []
2656
2674
if disable_build_check :
2657
2675
service_args = ["--disable-build-check" ]
@@ -2662,10 +2680,13 @@ def get_local_driver(
2662
2680
with uc_lock : # Avoid multithreaded issues
2663
2681
uc_driver_version = get_uc_driver_version ()
2664
2682
if (
2665
- uc_driver_version != use_version
2666
- and use_version != "latest"
2683
+ (
2684
+ uc_driver_version != use_version
2685
+ and use_version != "latest"
2686
+ )
2687
+ or not os .path .exists (LOCAL_UC_DRIVER )
2667
2688
):
2668
- if IS_ARM_MAC :
2689
+ if IS_ARM_MAC and os . path . exists ( LOCAL_UC_DRIVER ) :
2669
2690
pass # Already taken care of in sb_install
2670
2691
elif os .path .exists (LOCAL_CHROMEDRIVER ):
2671
2692
shutil .copyfile (
@@ -2706,53 +2727,62 @@ def get_local_driver(
2706
2727
chrome_options .arguments .remove (
2707
2728
"--headless"
2708
2729
)
2709
- cert = "unable to get local issuer certificate"
2710
2730
uc_chrome_version = None
2711
2731
if (
2712
2732
use_version .isnumeric ()
2713
2733
and int (use_version ) >= 72
2714
2734
):
2715
2735
uc_chrome_version = int (use_version )
2716
- uc_lock = fasteners .InterProcessLock (
2717
- constants .MultiBrowser .DRIVER_FIXING_LOCK
2718
- )
2719
- with uc_lock : # Avoid multithreaded issues
2720
- cdp_events = uc_cdp_events
2721
- try :
2722
- uc_path = None
2723
- if os .path .exists (LOCAL_UC_DRIVER ):
2724
- uc_path = LOCAL_UC_DRIVER
2725
- uc_path = os .path .realpath (uc_path )
2726
- driver = undetected .Chrome (
2727
- options = chrome_options ,
2728
- user_data_dir = user_data_dir ,
2729
- driver_executable_path = uc_path ,
2730
- enable_cdp_events = cdp_events ,
2731
- headless = False , # Xvfb needed!
2732
- version_main = uc_chrome_version ,
2733
- use_subprocess = True , # Always!
2734
- )
2735
- except URLError as e :
2736
- if (
2737
- cert in e .args [0 ]
2738
- and "darwin" in PLATFORM
2739
- ):
2736
+ cdp_events = uc_cdp_events
2737
+ cert = "unable to get local issuer certificate"
2738
+ mac_certificate_error = False
2739
+ try :
2740
+ uc_path = None
2741
+ if os .path .exists (LOCAL_UC_DRIVER ):
2742
+ uc_path = LOCAL_UC_DRIVER
2743
+ uc_path = os .path .realpath (uc_path )
2744
+ driver = undetected .Chrome (
2745
+ options = chrome_options ,
2746
+ user_data_dir = user_data_dir ,
2747
+ driver_executable_path = uc_path ,
2748
+ enable_cdp_events = cdp_events ,
2749
+ headless = False , # Xvfb needed!
2750
+ version_main = uc_chrome_version ,
2751
+ use_subprocess = True , # Always!
2752
+ )
2753
+ except URLError as e :
2754
+ if (
2755
+ cert in e .args [0 ]
2756
+ and "darwin" in PLATFORM
2757
+ ):
2758
+ mac_certificate_error = True
2759
+ else :
2760
+ raise
2761
+ if mac_certificate_error :
2762
+ cf_lock_path = (
2763
+ constants .MultiBrowser .CERT_FIXING_LOCK
2764
+ )
2765
+ cf_lock = fasteners .InterProcessLock (
2766
+ constants .MultiBrowser .CERT_FIXING_LOCK
2767
+ )
2768
+ if not os .path .exists (cf_lock_path ):
2769
+ # Avoid multithreaded issues
2770
+ with cf_lock :
2771
+ # Install Python Certificates (MAC)
2740
2772
os .system (
2741
2773
r"bash /Applications/Python*/"
2742
2774
r"Install\ "
2743
2775
r"Certificates.command"
2744
2776
)
2745
- driver = undetected .Chrome (
2746
- options = chrome_options ,
2747
- user_data_dir = user_data_dir ,
2748
- driver_executable_path = uc_path ,
2749
- enable_cdp_events = cdp_events ,
2750
- headless = False , # Xvfb needed!
2751
- version_main = uc_chrome_version ,
2752
- use_subprocess = True , # Always!
2753
- )
2754
- else :
2755
- raise
2777
+ driver = undetected .Chrome (
2778
+ options = chrome_options ,
2779
+ user_data_dir = user_data_dir ,
2780
+ driver_executable_path = uc_path ,
2781
+ enable_cdp_events = cdp_events ,
2782
+ headless = False , # Xvfb needed!
2783
+ version_main = uc_chrome_version ,
2784
+ use_subprocess = True , # Always!
2785
+ )
2756
2786
else :
2757
2787
service = ChromeService (
2758
2788
executable_path = LOCAL_CHROMEDRIVER ,
0 commit comments