@@ -293,7 +293,17 @@ def extend_driver(
293293 )
294294 if hasattr (driver , "proxy" ):
295295 driver .set_wire_proxy = DM .set_wire_proxy
296+ completed_loads = []
297+ for ext_dir in sb_config ._ext_dirs :
298+ with suppress (Exception ):
299+ if ext_dir not in completed_loads :
300+ completed_loads .append (ext_dir )
301+ if not use_uc and os .path .exists (os .path .abspath (ext_dir )):
302+ driver .webextension .install (os .path .abspath (ext_dir ))
296303 if proxy_auth :
304+ with suppress (Exception ):
305+ if not use_uc and os .path .exists (proxy_helper .PROXY_DIR_PATH ):
306+ driver .webextension .install (proxy_helper .PROXY_DIR_PATH )
297307 # Proxy needs a moment to load in Manifest V3
298308 if use_uc :
299309 time .sleep (0.14 )
@@ -2087,6 +2097,7 @@ def _add_chrome_proxy_extension(
20872097 """Implementation of https://stackoverflow.com/a/35293284/7058266
20882098 for https://stackoverflow.com/q/12848327/7058266
20892099 (Run Selenium on a proxy server that requires authentication.)"""
2100+ zip_it = False
20902101 args = " " .join (sys .argv )
20912102 bypass_list = proxy_bypass_list
20922103 if (
@@ -2467,13 +2478,27 @@ def _set_chrome_options(
24672478 extension_zip_list = extension_zip .split ("," )
24682479 for extension_zip_item in extension_zip_list :
24692480 abs_path = os .path .abspath (extension_zip_item )
2470- chrome_options .add_extension (abs_path )
2481+ if os .path .exists (abs_path ):
2482+ try :
2483+ abs_path_dir = os .path .join (
2484+ DOWNLOADS_FOLDER , abs_path .split ("." )[0 ]
2485+ )
2486+ _unzip_to_new_folder (abs_path , abs_path_dir )
2487+ chrome_options = add_chrome_ext_dir (
2488+ chrome_options , abs_path_dir
2489+ )
2490+ sb_config ._ext_dirs .append (abs_path_dir )
2491+ except Exception :
2492+ with suppress (Exception ):
2493+ chrome_options .add_extension (abs_path )
24712494 if extension_dir :
24722495 # load-extension input can be a comma-separated list
24732496 abs_path = (
24742497 "," .join (os .path .abspath (p ) for p in extension_dir .split ("," ))
24752498 )
24762499 chrome_options = add_chrome_ext_dir (chrome_options , abs_path )
2500+ for p in extension_dir .split ("," ):
2501+ sb_config ._ext_dirs .append (os .path .abspath (p ))
24772502 if (
24782503 page_load_strategy
24792504 and page_load_strategy .lower () in ["eager" , "none" ]
@@ -2508,37 +2533,32 @@ def _set_chrome_options(
25082533 if (settings .DISABLE_CSP_ON_CHROME or disable_csp ) and not headless :
25092534 # Headless Chrome does not support extensions, which are required
25102535 # for disabling the Content Security Policy on Chrome.
2511- if is_using_uc (undetectable , browser_name ):
2512- disable_csp_zip = DISABLE_CSP_ZIP_PATH
2513- disable_csp_dir = os .path .join (DOWNLOADS_FOLDER , "disable_csp" )
2514- _unzip_to_new_folder (disable_csp_zip , disable_csp_dir )
2515- chrome_options = add_chrome_ext_dir (
2516- chrome_options , disable_csp_dir
2517- )
2518- else :
2519- chrome_options = _add_chrome_disable_csp_extension (chrome_options )
2536+ disable_csp_zip = DISABLE_CSP_ZIP_PATH
2537+ disable_csp_dir = os .path .join (DOWNLOADS_FOLDER , "disable_csp" )
2538+ _unzip_to_new_folder (disable_csp_zip , disable_csp_dir )
2539+ chrome_options = add_chrome_ext_dir (
2540+ chrome_options , disable_csp_dir
2541+ )
2542+ sb_config ._ext_dirs .append (disable_csp_dir )
25202543 if ad_block_on and not headless :
25212544 # Headless Chrome does not support extensions.
2522- if is_using_uc (undetectable , browser_name ):
2523- ad_block_zip = AD_BLOCK_ZIP_PATH
2524- ad_block_dir = os .path .join (DOWNLOADS_FOLDER , "ad_block" )
2525- _unzip_to_new_folder (ad_block_zip , ad_block_dir )
2526- chrome_options = add_chrome_ext_dir (chrome_options , ad_block_dir )
2527- else :
2528- chrome_options = _add_chrome_ad_block_extension (chrome_options )
2545+ ad_block_zip = AD_BLOCK_ZIP_PATH
2546+ ad_block_dir = os .path .join (DOWNLOADS_FOLDER , "ad_block" )
2547+ _unzip_to_new_folder (ad_block_zip , ad_block_dir )
2548+ chrome_options = add_chrome_ext_dir (chrome_options , ad_block_dir )
2549+ sb_config ._ext_dirs .append (ad_block_dir )
25292550 if recorder_ext and not headless :
2530- if is_using_uc (undetectable , browser_name ):
2531- recorder_zip = RECORDER_ZIP_PATH
2532- recorder_dir = os .path .join (DOWNLOADS_FOLDER , "recorder" )
2533- _unzip_to_new_folder (recorder_zip , recorder_dir )
2534- chrome_options = add_chrome_ext_dir (chrome_options , recorder_dir )
2535- else :
2536- chrome_options = _add_chrome_recorder_extension (chrome_options )
2551+ recorder_zip = RECORDER_ZIP_PATH
2552+ recorder_dir = os .path .join (DOWNLOADS_FOLDER , "recorder" )
2553+ _unzip_to_new_folder (recorder_zip , recorder_dir )
2554+ chrome_options = add_chrome_ext_dir (chrome_options , recorder_dir )
2555+ sb_config ._ext_dirs .append (recorder_dir )
25372556 if chromium_arg and "sbase" in chromium_arg :
25382557 sbase_ext_zip = SBASE_EXT_ZIP_PATH
25392558 sbase_ext_dir = os .path .join (DOWNLOADS_FOLDER , "sbase_ext" )
25402559 _unzip_to_new_folder (sbase_ext_zip , sbase_ext_dir )
25412560 chrome_options = add_chrome_ext_dir (chrome_options , sbase_ext_dir )
2561+ sb_config ._ext_dirs .append (sbase_ext_dir )
25422562 if proxy_string :
25432563 if proxy_auth :
25442564 zip_it = True
@@ -2724,6 +2744,10 @@ def _set_chrome_options(
27242744 chrome_options .add_argument ("--disable-features=%s" % d_f_string )
27252745 if proxy_auth :
27262746 chrome_options .add_argument ("--test-type" )
2747+ if proxy_auth or sb_config ._ext_dirs :
2748+ if not is_using_uc (undetectable , browser_name ):
2749+ chrome_options .enable_webextensions = True
2750+ chrome_options .enable_bidi = True
27272751 if (
27282752 is_using_uc (undetectable , browser_name )
27292753 and (
@@ -2988,6 +3012,7 @@ def get_driver(
29883012 device_pixel_ratio = None ,
29893013 browser = None , # A duplicate of browser_name to avoid confusion
29903014):
3015+ sb_config ._ext_dirs = []
29913016 driver_dir = DRIVER_DIR
29923017 if (
29933018 hasattr (sb_config , "binary_location" )
0 commit comments