11import fasteners
22import logging
33import os
4+ import platform
45import re
56import shutil
67import subprocess
4950PROXY_DIR_PATH = proxy_helper .PROXY_DIR_PATH
5051PROXY_DIR_LOCK = proxy_helper .PROXY_DIR_LOCK
5152PLATFORM = sys .platform
53+ IS_ARM_MAC = False
54+ if PLATFORM .endswith ("darwin" ) and "arm" in platform .processor ().lower ():
55+ IS_ARM_MAC = True
5256IS_WINDOWS = False
5357LOCAL_CHROMEDRIVER = None
5458LOCAL_GECKODRIVER = None
@@ -130,6 +134,25 @@ def chromedriver_on_path():
130134 return None
131135
132136
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+
133156def edgedriver_on_path ():
134157 return os .path .exists (LOCAL_EDGEDRIVER )
135158
@@ -2501,13 +2524,25 @@ def get_local_driver(
25012524 except Exception :
25022525 pass
25032526 disable_build_check = False
2527+ uc_driver_version = None
2528+ if IS_ARM_MAC :
2529+ uc_driver_version = get_uc_driver_version ()
25042530 if (
25052531 LOCAL_CHROMEDRIVER
25062532 and os .path .exists (LOCAL_CHROMEDRIVER )
25072533 and (
25082534 use_version == driver_version
25092535 or use_version == "latest"
25102536 )
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+ )
25112546 ):
25122547 try :
25132548 make_driver_executable_if_not (LOCAL_CHROMEDRIVER )
@@ -2527,6 +2562,16 @@ def get_local_driver(
25272562 or driver_version != "72"
25282563 )
25292564 )
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+ )
25302575 ):
25312576 # chromedriver download needed in the seleniumbase/drivers dir
25322577 from seleniumbase .console_scripts import sb_install
@@ -2538,11 +2583,14 @@ def get_local_driver(
25382583 msg = "chromedriver update needed. Getting it now:"
25392584 if not path_chromedriver :
25402585 msg = "chromedriver not found. Getting it now:"
2541-
25422586 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
25432590 try :
25442591 sb_install .main (
2545- override = "chromedriver %s" % use_version
2592+ override = "chromedriver %s" % use_version ,
2593+ intel_for_uc = intel_for_uc ,
25462594 )
25472595 except Exception :
25482596 d_latest = get_latest_chromedriver_version ()
@@ -2613,27 +2661,15 @@ def get_local_driver(
26132661 uc_lock = fasteners .InterProcessLock (
26142662 constants .MultiBrowser .DRIVER_FIXING_LOCK
26152663 )
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 ()
26322666 if (
26332667 uc_driver_version != use_version
26342668 and use_version != "latest"
26352669 ):
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 ):
26372673 shutil .copyfile (
26382674 LOCAL_CHROMEDRIVER , LOCAL_UC_DRIVER
26392675 )
@@ -2683,7 +2719,7 @@ def get_local_driver(
26832719 uc_lock = fasteners .InterProcessLock (
26842720 constants .MultiBrowser .DRIVER_FIXING_LOCK
26852721 )
2686- with uc_lock :
2722+ with uc_lock : # Avoid multithreaded issues
26872723 try :
26882724 uc_path = None
26892725 if os .path .exists (LOCAL_UC_DRIVER ):
0 commit comments