16
16
from selenium .webdriver .edge .service import Service as EdgeService
17
17
from selenium .webdriver .firefox .service import Service as FirefoxService
18
18
from selenium .webdriver .safari .service import Service as SafariService
19
+ from seleniumbase import config as sb_config
19
20
from seleniumbase import decorators
20
21
from seleniumbase import drivers # webdriver storage folder for SeleniumBase
21
22
from seleniumbase import extensions # browser extensions storage folder
@@ -1564,11 +1565,9 @@ def get_remote_driver(
1564
1565
extra_caps = {}
1565
1566
if cap_file :
1566
1567
from seleniumbase .core import capabilities_parser
1567
-
1568
1568
desired_caps = capabilities_parser .get_desired_capabilities (cap_file )
1569
1569
if cap_string :
1570
1570
import json
1571
-
1572
1571
try :
1573
1572
extra_caps = json .loads (str (cap_string ))
1574
1573
except Exception as e :
@@ -2073,7 +2072,6 @@ def get_local_driver(
2073
2072
"IE Browser is for Windows-based systems only!"
2074
2073
)
2075
2074
from selenium .webdriver .ie .options import Options
2076
-
2077
2075
ie_options = Options ()
2078
2076
ie_options .ignore_protected_mode_settings = True
2079
2077
ie_options .ignore_zoom_level = True
@@ -2726,8 +2724,6 @@ def get_local_driver(
2726
2724
if is_using_uc (undetectable , browser_name ):
2727
2725
uc_driver_version = get_uc_driver_version ()
2728
2726
if multi_proxy :
2729
- from seleniumbase import config as sb_config
2730
-
2731
2727
sb_config .multi_proxy = True
2732
2728
use_version = find_chromedriver_version_to_use (
2733
2729
use_version , driver_version
@@ -2983,7 +2979,6 @@ def get_local_driver(
2983
2979
if is_using_uc (undetectable , browser_name ):
2984
2980
from seleniumbase import undetected
2985
2981
from urllib .error import URLError
2986
-
2987
2982
if IS_LINUX :
2988
2983
if "--headless" in (
2989
2984
chrome_options .arguments
@@ -3007,52 +3002,70 @@ def get_local_driver(
3007
3002
chrome_options .add_experimental_option (
3008
3003
"w3c" , True
3009
3004
)
3005
+ if (
3006
+ (not user_agent or "Headless" in user_agent )
3007
+ and uc_chrome_version
3008
+ and uc_chrome_version >= 117
3009
+ and (headless or headless2 )
3010
+ and hasattr (sb_config , "uc_agent_cache" )
3011
+ ):
3012
+ user_agent = sb_config .uc_agent_cache
3013
+ chrome_options .add_argument (
3014
+ "--user-agent=%s" % user_agent
3015
+ )
3010
3016
try :
3011
3017
if (
3012
- uc_chrome_version
3018
+ (
3019
+ not user_agent
3020
+ or "Headless" in user_agent
3021
+ )
3022
+ and uc_chrome_version
3013
3023
and uc_chrome_version >= 117
3014
3024
and (headless or headless2 )
3015
- and not user_agent
3016
3025
):
3026
+ from seleniumbase .console_scripts import (
3027
+ sb_install
3028
+ )
3029
+ sb_config .uc_user_agent_cache = True
3017
3030
headless_options = _set_chrome_options (
3018
3031
browser_name ,
3019
3032
downloads_path ,
3020
3033
True , # headless
3021
3034
locale_code ,
3022
- proxy_string ,
3023
- proxy_auth ,
3024
- proxy_user ,
3025
- proxy_pass ,
3026
- proxy_bypass_list ,
3027
- proxy_pac_url ,
3028
- multi_proxy ,
3029
- user_agent ,
3030
- recorder_ext ,
3035
+ None , # proxy_string
3036
+ None , # proxy_auth
3037
+ None , # proxy_user
3038
+ None , # proxy_pass
3039
+ None , # proxy_bypass_list
3040
+ None , # proxy_pac_url
3041
+ None , # multi_proxy
3042
+ None , # user_agent
3043
+ None , # recorder_ext
3031
3044
disable_js ,
3032
3045
disable_csp ,
3033
3046
enable_ws ,
3034
3047
enable_sync ,
3035
3048
use_auto_ext ,
3036
- False , # Undetectable
3037
- uc_cdp_events ,
3038
- uc_subprocess ,
3049
+ False , # undetectable
3050
+ False , # uc_cdp_events
3051
+ False , # uc_subprocess
3039
3052
no_sandbox ,
3040
3053
disable_gpu ,
3041
3054
False , # headless2
3042
3055
incognito ,
3043
3056
guest_mode ,
3044
3057
dark_mode ,
3045
- devtools ,
3058
+ None , # devtools
3046
3059
remote_debug ,
3047
3060
enable_3d_apis ,
3048
3061
swiftshader ,
3049
- ad_block_on ,
3062
+ None , # ad_block_on
3050
3063
block_images ,
3051
3064
do_not_track ,
3052
- chromium_arg ,
3053
- user_data_dir ,
3054
- extension_zip ,
3055
- extension_dir ,
3065
+ None , # chromium_arg
3066
+ None , # user_data_dir
3067
+ None , # extension_zip
3068
+ None , # extension_dir
3056
3069
binary_location ,
3057
3070
driver_version ,
3058
3071
page_load_strategy ,
@@ -3064,7 +3077,17 @@ def get_local_driver(
3064
3077
device_height ,
3065
3078
device_pixel_ratio ,
3066
3079
)
3067
- if not path_chromedriver :
3080
+ if (
3081
+ not path_chromedriver
3082
+ or (
3083
+ ch_driver_version
3084
+ and use_version
3085
+ and (
3086
+ int (ch_driver_version )
3087
+ < int (use_version )
3088
+ )
3089
+ )
3090
+ ):
3068
3091
sb_install .main (
3069
3092
override = "chromedriver %s"
3070
3093
% use_version ,
@@ -3091,12 +3114,16 @@ def get_local_driver(
3091
3114
service = service ,
3092
3115
options = headless_options ,
3093
3116
)
3094
- user_agent = driver .execute_script (
3095
- "return navigator.userAgent;"
3096
- ).replace ("Headless" , "" )
3097
- chrome_options .add_argument (
3098
- "--user-agent=%s" % user_agent
3099
- )
3117
+ try :
3118
+ user_agent = driver .execute_script (
3119
+ "return navigator.userAgent;"
3120
+ ).replace ("Headless" , "" )
3121
+ chrome_options .add_argument (
3122
+ "--user-agent=%s" % user_agent
3123
+ )
3124
+ sb_config .uc_agent_cache = user_agent
3125
+ except Exception :
3126
+ pass
3100
3127
driver .quit ()
3101
3128
except Exception :
3102
3129
pass
@@ -3213,46 +3240,45 @@ def get_local_driver(
3213
3240
mcv = find_chromedriver_version_to_use (
3214
3241
mcv , driver_version
3215
3242
)
3216
- headless = True
3217
3243
headless_options = _set_chrome_options (
3218
3244
browser_name ,
3219
3245
downloads_path ,
3220
- headless ,
3246
+ True , # headless
3221
3247
locale_code ,
3222
- proxy_string ,
3223
- proxy_auth ,
3224
- proxy_user ,
3225
- proxy_pass ,
3226
- proxy_bypass_list ,
3227
- proxy_pac_url ,
3228
- multi_proxy ,
3229
- user_agent ,
3230
- recorder_ext ,
3248
+ None , # proxy_string
3249
+ None , # proxy_auth
3250
+ None , # proxy_user
3251
+ None , # proxy_pass
3252
+ None , # proxy_bypass_list
3253
+ None , # proxy_pac_url
3254
+ None , # multi_proxy
3255
+ None , # user_agent
3256
+ None , # recorder_ext
3231
3257
disable_js ,
3232
3258
disable_csp ,
3233
3259
enable_ws ,
3234
3260
enable_sync ,
3235
3261
use_auto_ext ,
3236
- undetectable ,
3237
- uc_cdp_events ,
3238
- uc_subprocess ,
3262
+ False , # undetectable
3263
+ False , # uc_cdp_events
3264
+ False , # uc_subprocess
3239
3265
no_sandbox ,
3240
3266
disable_gpu ,
3241
- headless2 ,
3267
+ False , # headless2
3242
3268
incognito ,
3243
3269
guest_mode ,
3244
3270
dark_mode ,
3245
- devtools ,
3271
+ None , # devtools
3246
3272
remote_debug ,
3247
3273
enable_3d_apis ,
3248
3274
swiftshader ,
3249
- ad_block_on ,
3275
+ None , # ad_block_on
3250
3276
block_images ,
3251
3277
do_not_track ,
3252
- chromium_arg ,
3253
- user_data_dir ,
3254
- extension_zip ,
3255
- extension_dir ,
3278
+ None , # chromium_arg
3279
+ None , # user_data_dir
3280
+ None , # extension_zip
3281
+ None , # extension_dir
3256
3282
binary_location ,
3257
3283
driver_version ,
3258
3284
page_load_strategy ,
0 commit comments