Skip to content

Commit ee01fbf

Browse files
committed
Update UC Mode
1 parent 86e0eef commit ee01fbf

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,46 @@ def has_cf(text):
177177
return False
178178

179179

180-
def uc_open(driver, url):
180+
def uc_special_open_if_cf(driver, url):
181181
if (
182182
(url.startswith("http:") or url.startswith("https:"))
183183
and has_cf(requests_get(url).text)
184184
):
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:")):
185220
driver.execute_script('window.open("%s","_blank");' % url)
186221
driver.reconnect(2.65)
187222
driver.close()
@@ -3290,7 +3325,14 @@ def get_local_driver(
32903325
)
32913326
driver.open = driver.get # Save copy of original
32923327
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+
)
32943336
return driver
32953337
else: # Running headless on Linux (and not using --uc)
32963338
try:

seleniumbase/undetected/patcher.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ def gen_call_function_js_cache_name(match):
208208
gen_js_whitespaces,
209209
file_bin,
210210
)
211+
file_bin = re.sub(
212+
b"window\\.cdc_[a-zA-Z0-9]{22}_(Array|Promise|Symbol)",
213+
b"window\\.ccd_adoQpoasnaf67pfcZLmcfl_(Array|Promise|Symbol)",
214+
file_bin,
215+
)
211216
file_bin = re.sub(
212217
b"'\\$cdc_[a-zA-Z0-9]{22}_';",
213218
gen_call_function_js_cache_name,

0 commit comments

Comments
 (0)