@@ -168,6 +168,32 @@ def get_uc_driver_version():
168
168
return uc_driver_version
169
169
170
170
171
+ def has_cf (text ):
172
+ if (
173
+ "<title>Just a moment...</title>" in text
174
+ or 'id="challenge-error-text"' in text
175
+ or 'action="/?__cf_chl_f_tk' in text
176
+ or 'id="challenge-form"' in text
177
+ or "window._cf_chl_opt" in text
178
+ ):
179
+ return True
180
+ return False
181
+
182
+
183
+ def uc_open (driver , url ):
184
+ if (
185
+ (url .startswith ("http:" ) or url .startswith ("https:" ))
186
+ and has_cf (requests_get (url ).text )
187
+ ):
188
+ driver .execute_script ('window.open("%s","_blank");' % url )
189
+ time .sleep (2.75 )
190
+ driver .execute_script ("window.close();" )
191
+ driver .switch_to .window (driver .window_handles [- 1 ])
192
+ else :
193
+ driver .open (url ) # The original one
194
+ return None
195
+
196
+
171
197
def edgedriver_on_path ():
172
198
return os .path .exists (LOCAL_EDGEDRIVER )
173
199
@@ -742,6 +768,9 @@ def _set_chrome_options(
742
768
chrome_options .add_argument ("--use-gl=swiftshader" )
743
769
elif not is_using_uc (undetectable , browser_name ):
744
770
chrome_options .add_argument ("--disable-gpu" )
771
+ if not IS_LINUX and is_using_uc (undetectable , browser_name ):
772
+ chrome_options .add_argument ("--disable-dev-shm-usage" )
773
+ chrome_options .add_argument ("--disable-application-cache" )
745
774
if IS_LINUX :
746
775
chrome_options .add_argument ("--disable-dev-shm-usage" )
747
776
if is_using_uc (undetectable , browser_name ):
@@ -3008,6 +3037,7 @@ def get_local_driver(
3008
3037
or not IS_LINUX
3009
3038
or is_using_uc (undetectable , browser_name )
3010
3039
):
3040
+ uc_activated = False
3011
3041
try :
3012
3042
if (
3013
3043
os .path .exists (LOCAL_CHROMEDRIVER )
@@ -3051,6 +3081,7 @@ def get_local_driver(
3051
3081
version_main = uc_chrome_version ,
3052
3082
use_subprocess = True , # Always!
3053
3083
)
3084
+ uc_activated = True
3054
3085
except URLError as e :
3055
3086
if cert in e .args [0 ] and IS_MAC :
3056
3087
mac_certificate_error = True
@@ -3082,6 +3113,7 @@ def get_local_driver(
3082
3113
version_main = uc_chrome_version ,
3083
3114
use_subprocess = True , # Always!
3084
3115
)
3116
+ uc_activated = True
3085
3117
else :
3086
3118
service = ChromeService (
3087
3119
executable_path = LOCAL_CHROMEDRIVER ,
@@ -3246,6 +3278,9 @@ def get_local_driver(
3246
3278
service_args = ["--disable-build-check" ],
3247
3279
options = chrome_options ,
3248
3280
)
3281
+ driver .open = driver .get # Save copy of original
3282
+ if uc_activated :
3283
+ driver .get = lambda url : uc_open (driver , url )
3249
3284
return driver
3250
3285
else : # Running headless on Linux (and not using --uc)
3251
3286
try :
0 commit comments