@@ -177,11 +177,46 @@ def has_cf(text):
177
177
return False
178
178
179
179
180
- def uc_open (driver , url ):
180
+ def uc_special_open_if_cf (driver , url ):
181
181
if (
182
182
(url .startswith ("http:" ) or url .startswith ("https:" ))
183
183
and has_cf (requests_get (url ).text )
184
184
):
185
+ with driver :
186
+ time .sleep (0.25 )
187
+ driver .execute_script ('window.open("%s","_blank");' % url )
188
+ driver .close ()
189
+ driver .switch_to .window (driver .window_handles [- 1 ])
190
+ else :
191
+ driver .open (url ) # The original one
192
+ return None
193
+
194
+
195
+ def uc_open (driver , url ):
196
+ if (url .startswith ("http:" ) or url .startswith ("https:" )):
197
+ with driver :
198
+ time .sleep (0.25 )
199
+ driver .open (url )
200
+ else :
201
+ driver .open (url ) # The original one
202
+ return None
203
+
204
+
205
+ def uc_open_with_tab (driver , url ):
206
+ if (url .startswith ("http:" ) or url .startswith ("https:" )):
207
+ with driver :
208
+ time .sleep (0.25 )
209
+ driver .execute_script ('window.open("%s","_blank");' % url )
210
+ driver .close ()
211
+ driver .switch_to .window (driver .window_handles [- 1 ])
212
+ else :
213
+ driver .open (url ) # The original one
214
+ return None
215
+
216
+
217
+ def uc_open_with_reconnect (driver , url ):
218
+ """Open a url, then reconnect with UC before switching to the window."""
219
+ if (url .startswith ("http:" ) or url .startswith ("https:" )):
185
220
driver .execute_script ('window.open("%s","_blank");' % url )
186
221
driver .reconnect (2.65 )
187
222
driver .close ()
@@ -3290,7 +3325,14 @@ def get_local_driver(
3290
3325
)
3291
3326
driver .open = driver .get # Save copy of original
3292
3327
if uc_activated :
3293
- driver .get = lambda url : uc_open (driver , url )
3328
+ driver .get = lambda url : uc_special_open_if_cf (driver , url )
3329
+ driver .uc_open = lambda url : uc_open (driver , url )
3330
+ driver .uc_open_with_tab = (
3331
+ lambda url : uc_open_with_tab (driver , url )
3332
+ )
3333
+ driver .uc_open_with_reconnect = (
3334
+ lambda url : uc_open_with_reconnect (driver , url )
3335
+ )
3294
3336
return driver
3295
3337
else : # Running headless on Linux (and not using --uc)
3296
3338
try :
0 commit comments