1
1
import fasteners
2
2
import logging
3
3
import os
4
+ import platform
4
5
import re
5
6
import shutil
6
7
import subprocess
49
50
PROXY_DIR_PATH = proxy_helper .PROXY_DIR_PATH
50
51
PROXY_DIR_LOCK = proxy_helper .PROXY_DIR_LOCK
51
52
PLATFORM = sys .platform
53
+ IS_ARM_MAC = False
54
+ if PLATFORM .endswith ("darwin" ) and "arm" in platform .processor ().lower ():
55
+ IS_ARM_MAC = True
52
56
IS_WINDOWS = False
53
57
LOCAL_CHROMEDRIVER = None
54
58
LOCAL_GECKODRIVER = None
@@ -130,6 +134,25 @@ def chromedriver_on_path():
130
134
return None
131
135
132
136
137
+ def get_uc_driver_version ():
138
+ uc_driver_version = None
139
+ if os .path .exists (LOCAL_UC_DRIVER ):
140
+ try :
141
+ output = subprocess .check_output (
142
+ "%s --version" % LOCAL_UC_DRIVER , shell = True
143
+ )
144
+ if IS_WINDOWS :
145
+ output = output .decode ("latin1" )
146
+ else :
147
+ output = output .decode ("utf-8" )
148
+ output = output .split (" " )[1 ].split ("." )[0 ]
149
+ if int (output ) >= 72 :
150
+ uc_driver_version = output
151
+ except Exception :
152
+ pass
153
+ return uc_driver_version
154
+
155
+
133
156
def edgedriver_on_path ():
134
157
return os .path .exists (LOCAL_EDGEDRIVER )
135
158
@@ -2501,13 +2524,25 @@ def get_local_driver(
2501
2524
except Exception :
2502
2525
pass
2503
2526
disable_build_check = False
2527
+ uc_driver_version = None
2528
+ if IS_ARM_MAC :
2529
+ uc_driver_version = get_uc_driver_version ()
2504
2530
if (
2505
2531
LOCAL_CHROMEDRIVER
2506
2532
and os .path .exists (LOCAL_CHROMEDRIVER )
2507
2533
and (
2508
2534
use_version == driver_version
2509
2535
or use_version == "latest"
2510
2536
)
2537
+ and (
2538
+ not is_using_uc (undetectable , browser_name )
2539
+ or not IS_ARM_MAC
2540
+ )
2541
+ or (
2542
+ is_using_uc (undetectable , browser_name )
2543
+ and IS_ARM_MAC
2544
+ and uc_driver_version == use_version
2545
+ )
2511
2546
):
2512
2547
try :
2513
2548
make_driver_executable_if_not (LOCAL_CHROMEDRIVER )
@@ -2527,6 +2562,16 @@ def get_local_driver(
2527
2562
or driver_version != "72"
2528
2563
)
2529
2564
)
2565
+ or (
2566
+ is_using_uc (undetectable , browser_name )
2567
+ and not os .path .exists (LOCAL_UC_DRIVER )
2568
+ )
2569
+ or (
2570
+ is_using_uc (undetectable , browser_name )
2571
+ and IS_ARM_MAC
2572
+ and use_version != "latest"
2573
+ and uc_driver_version != use_version
2574
+ )
2530
2575
):
2531
2576
# chromedriver download needed in the seleniumbase/drivers dir
2532
2577
from seleniumbase .console_scripts import sb_install
@@ -2538,11 +2583,14 @@ def get_local_driver(
2538
2583
msg = "chromedriver update needed. Getting it now:"
2539
2584
if not path_chromedriver :
2540
2585
msg = "chromedriver not found. Getting it now:"
2541
-
2542
2586
print ("\n Warning: %s" % msg )
2587
+ intel_for_uc = False
2588
+ if IS_ARM_MAC and is_using_uc (undetectable , browser_name ):
2589
+ intel_for_uc = True # Use Intel's driver for UC Mode
2543
2590
try :
2544
2591
sb_install .main (
2545
- override = "chromedriver %s" % use_version
2592
+ override = "chromedriver %s" % use_version ,
2593
+ intel_for_uc = intel_for_uc ,
2546
2594
)
2547
2595
except Exception :
2548
2596
d_latest = get_latest_chromedriver_version ()
@@ -2613,27 +2661,15 @@ def get_local_driver(
2613
2661
uc_lock = fasteners .InterProcessLock (
2614
2662
constants .MultiBrowser .DRIVER_FIXING_LOCK
2615
2663
)
2616
- with uc_lock : # No UC multithreaded tests
2617
- uc_driver_version = None
2618
- if os .path .exists (LOCAL_UC_DRIVER ):
2619
- try :
2620
- output = subprocess .check_output (
2621
- "%s --version" % LOCAL_UC_DRIVER , shell = True
2622
- )
2623
- if IS_WINDOWS :
2624
- output = output .decode ("latin1" )
2625
- else :
2626
- output = output .decode ("utf-8" )
2627
- output = output .split (" " )[1 ].split ("." )[0 ]
2628
- if int (output ) >= 72 :
2629
- uc_driver_version = output
2630
- except Exception :
2631
- pass
2664
+ with uc_lock : # Avoid multithreaded issues
2665
+ uc_driver_version = get_uc_driver_version ()
2632
2666
if (
2633
2667
uc_driver_version != use_version
2634
2668
and use_version != "latest"
2635
2669
):
2636
- if os .path .exists (LOCAL_CHROMEDRIVER ):
2670
+ if IS_ARM_MAC :
2671
+ pass # Already taken care of in sb_install
2672
+ elif os .path .exists (LOCAL_CHROMEDRIVER ):
2637
2673
shutil .copyfile (
2638
2674
LOCAL_CHROMEDRIVER , LOCAL_UC_DRIVER
2639
2675
)
@@ -2683,7 +2719,7 @@ def get_local_driver(
2683
2719
uc_lock = fasteners .InterProcessLock (
2684
2720
constants .MultiBrowser .DRIVER_FIXING_LOCK
2685
2721
)
2686
- with uc_lock :
2722
+ with uc_lock : # Avoid multithreaded issues
2687
2723
try :
2688
2724
uc_path = None
2689
2725
if os .path .exists (LOCAL_UC_DRIVER ):
0 commit comments