@@ -333,6 +333,7 @@ def _set_chrome_options(
333333 undetectable ,
334334 no_sandbox ,
335335 disable_gpu ,
336+ headless2 ,
336337 incognito ,
337338 guest_mode ,
338339 devtools ,
@@ -505,7 +506,9 @@ def _set_chrome_options(
505506 "--disable-blink-features=AutomationControlled"
506507 )
507508 chrome_options .add_experimental_option ("useAutomationExtension" , False )
508- if headless :
509+ if headless2 :
510+ chrome_options .add_argument ("--headless=chrome" )
511+ elif headless :
509512 chrome_options .add_argument ("--headless" )
510513 if (settings .DISABLE_CSP_ON_CHROME or disable_csp ) and not headless :
511514 # Headless Chrome does not support extensions, which are required
@@ -865,6 +868,7 @@ def get_driver(
865868 undetectable = False ,
866869 no_sandbox = False ,
867870 disable_gpu = False ,
871+ headless2 = False ,
868872 incognito = False ,
869873 guest_mode = False ,
870874 devtools = False ,
@@ -943,20 +947,43 @@ def get_driver(
943947 raise Exception ('The proxy PAC URL must end with ".pac"!' )
944948 if proxy_pac_url and proxy_user and proxy_pass :
945949 proxy_auth = True
950+ if (
951+ is_using_uc (undetectable , browser_name )
952+ and "linux" not in PLATFORM
953+ and headless
954+ ):
955+ headless = False
956+ headless2 = True
946957 if (
947958 headless
948- and proxy_auth
959+ and (
960+ proxy_auth
961+ or ad_block_on
962+ or disable_csp
963+ or recorder_ext
964+ or extension_zip
965+ or extension_dir
966+ )
949967 and (
950968 browser_name == constants .Browser .GOOGLE_CHROME
951969 or browser_name == constants .Browser .EDGE
952970 )
953971 ):
954972 # Headless Chrome/Edge doesn't support extensions, which are
955- # required when using a proxy server that has authentication.
973+ # required when using a proxy server that has authentication,
974+ # or when using other SeleniumBase extensions (eg: Recorder).
956975 # Instead, base_case.py will use the SBVirtualDisplay when not
957976 # using Chrome's built-in headless mode. See link for details:
958977 # https://bugs.chromium.org/p/chromium/issues/detail?id=706008
959978 headless = False
979+ if "linux" not in PLATFORM :
980+ # Use the new headless mode on Chrome if not using Linux:
981+ # bugs.chromium.org/p/chromium/issues/detail?id=706008#c36
982+ # Although Linux is technically supported, there are a lot
983+ # of old versions of Chrome on Linux server machines, and
984+ # this mode requires a recent version of Chrome to work.
985+ # Specify "--headless2" as a pytest arg to use on Linux.
986+ headless2 = True
960987 if (
961988 browser_name == constants .Browser .GOOGLE_CHROME
962989 and user_data_dir
@@ -990,6 +1017,7 @@ def get_driver(
9901017 undetectable ,
9911018 no_sandbox ,
9921019 disable_gpu ,
1020+ headless2 ,
9931021 incognito ,
9941022 guest_mode ,
9951023 devtools ,
@@ -1033,6 +1061,7 @@ def get_driver(
10331061 undetectable ,
10341062 no_sandbox ,
10351063 disable_gpu ,
1064+ headless2 ,
10361065 incognito ,
10371066 guest_mode ,
10381067 devtools ,
@@ -1080,6 +1109,7 @@ def get_remote_driver(
10801109 undetectable ,
10811110 no_sandbox ,
10821111 disable_gpu ,
1112+ headless2 ,
10831113 incognito ,
10841114 guest_mode ,
10851115 devtools ,
@@ -1177,6 +1207,7 @@ def get_remote_driver(
11771207 undetectable ,
11781208 no_sandbox ,
11791209 disable_gpu ,
1210+ headless2 ,
11801211 incognito ,
11811212 guest_mode ,
11821213 devtools ,
@@ -1402,6 +1433,7 @@ def get_remote_driver(
14021433 undetectable ,
14031434 no_sandbox ,
14041435 disable_gpu ,
1436+ headless2 ,
14051437 incognito ,
14061438 guest_mode ,
14071439 devtools ,
@@ -1594,6 +1626,7 @@ def get_local_driver(
15941626 undetectable ,
15951627 no_sandbox ,
15961628 disable_gpu ,
1629+ headless2 ,
15971630 incognito ,
15981631 guest_mode ,
15991632 devtools ,
@@ -1893,7 +1926,9 @@ def get_local_driver(
18931926 edge_options .add_argument ("--disable-sync" )
18941927 if guest_mode :
18951928 edge_options .add_argument ("--guest" )
1896- if headless :
1929+ if headless2 :
1930+ edge_options .add_argument ("--headless=chrome" )
1931+ elif headless :
18971932 edge_options .add_argument ("--headless" )
18981933 if mobile_emulator :
18991934 emulator_settings = {}
@@ -2177,6 +2212,7 @@ def get_local_driver(
21772212 undetectable ,
21782213 no_sandbox ,
21792214 disable_gpu ,
2215+ headless2 ,
21802216 incognito ,
21812217 guest_mode ,
21822218 devtools ,
@@ -2237,6 +2273,7 @@ def get_local_driver(
22372273 undetectable ,
22382274 no_sandbox ,
22392275 disable_gpu ,
2276+ headless2 ,
22402277 incognito ,
22412278 guest_mode ,
22422279 devtools ,
@@ -2551,6 +2588,7 @@ def get_local_driver(
25512588 undetectable ,
25522589 no_sandbox ,
25532590 disable_gpu ,
2591+ headless2 ,
25542592 incognito ,
25552593 guest_mode ,
25562594 devtools ,
0 commit comments