Skip to content

Commit 121aade

Browse files
authored
Merge pull request #2109 from seleniumbase/update-recorder-uc-mode-and-print
Update Recorder Mode, UC Mode, and Smart Word-Wrap
2 parents 2df116d + 2b74696 commit 121aade

File tree

12 files changed

+134
-49
lines changed

12 files changed

+134
-49
lines changed

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
pip>=23.2.1
22
packaging>=23.1
33
setuptools>=68.0.0;python_version<"3.8"
4-
setuptools>=68.2.0;python_version>="3.8"
4+
setuptools>=68.2.2;python_version>="3.8"
55
wheel>=0.41.2
66
attrs>=23.1.0
77
certifi>=2023.7.22
88
filelock>=3.12.2;python_version<"3.8"
9-
filelock>=3.12.3;python_version>="3.8"
9+
filelock>=3.12.4;python_version>="3.8"
1010
platformdirs>=3.10.0
1111
parse>=1.19.1
1212
parse-type>=0.6.2

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.18.5"
2+
__version__ = "4.18.6"

seleniumbase/console_scripts/sb_print.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,15 @@ def main():
198198
new_sb_lines.append(line1)
199199
new_sb_lines.append(line2)
200200
continue
201-
if line.count("(") == 1 and line.count(")") == 1:
201+
if (
202+
line.count("(") >= 1
203+
and line.count("(") == line.count(")")
204+
):
202205
whitespace = line_length2 - len(line.lstrip())
203206
new_ws = line[0:whitespace] + " "
204-
line1 = line.split("(")[0] + "("
205-
line2 = new_ws + line.split("(")[1]
207+
first_paren = line.find("(")
208+
line1 = line[:first_paren + 1]
209+
line2 = new_ws + line[first_paren + 1:]
206210
if not ("):") in line2:
207211
new_sb_lines.append(line1)
208212
if get_width(line2) + w > console_width:
@@ -302,9 +306,7 @@ def main():
302306
continue
303307
elif line2.count(", ") == 1:
304308
line2a = line2.split(", ")[0] + ","
305-
line2b = new_ws + (
306-
line2.split(", ")[1]
307-
)
309+
line2b = new_ws + line2.split(", ")[1]
308310
new_sb_lines.append(line2a)
309311
new_sb_lines.append(line2b)
310312
continue

seleniumbase/core/browser_launcher.py

Lines changed: 98 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -666,11 +666,9 @@ def _set_chrome_options(
666666
chrome_options = webdriver.ChromeOptions()
667667
if is_using_uc(undetectable, browser_name):
668668
from seleniumbase import undetected
669-
670669
chrome_options = undetected.ChromeOptions()
671670
elif browser_name == constants.Browser.EDGE:
672671
chrome_options = webdriver.edge.options.Options()
673-
674672
prefs = {}
675673
prefs["download.default_directory"] = downloads_path
676674
prefs["local_discovery.notifications_enabled"] = False
@@ -2485,12 +2483,12 @@ def get_local_driver(
24852483
binary_location = binary_loc
24862484
if binary_location:
24872485
edge_options.binary_location = binary_location
2486+
service = EdgeService(
2487+
executable_path=LOCAL_EDGEDRIVER,
2488+
log_output=os.devnull,
2489+
service_args=["--disable-build-check"],
2490+
)
24882491
try:
2489-
service = EdgeService(
2490-
executable_path=LOCAL_EDGEDRIVER,
2491-
log_output=os.devnull,
2492-
service_args=["--disable-build-check"],
2493-
)
24942492
driver = Edge(service=service, options=edge_options)
24952493
except Exception as e:
24962494
if not hasattr(e, "msg"):
@@ -2512,11 +2510,6 @@ def get_local_driver(
25122510
"only supports MSEdge version "
25132511
)[1].split(" ")[0]
25142512
elif "DevToolsActivePort file doesn't exist" in e.msg:
2515-
service = EdgeService(
2516-
executable_path=LOCAL_EDGEDRIVER,
2517-
log_output=os.devnull,
2518-
service_args=["--disable-build-check"],
2519-
)
25202513
# https://stackoverflow.com/a/56638103/7058266
25212514
args = " ".join(sys.argv)
25222515
free_port = 9222
@@ -2550,11 +2543,6 @@ def get_local_driver(
25502543
_mark_driver_repaired()
25512544
except Exception:
25522545
pass
2553-
service = EdgeService(
2554-
executable_path=LOCAL_EDGEDRIVER,
2555-
log_output=os.devnull,
2556-
service_args=["--disable-build-check"],
2557-
)
25582546
driver = Edge(service=service, options=edge_options)
25592547
return extend_driver(driver)
25602548
elif browser_name == constants.Browser.SAFARI:
@@ -3019,6 +3007,99 @@ def get_local_driver(
30193007
chrome_options.add_experimental_option(
30203008
"w3c", True
30213009
)
3010+
try:
3011+
if (
3012+
uc_chrome_version
3013+
and uc_chrome_version >= 117
3014+
and (headless or headless2)
3015+
and not user_agent
3016+
):
3017+
headless_options = _set_chrome_options(
3018+
browser_name,
3019+
downloads_path,
3020+
True, # headless
3021+
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,
3031+
disable_js,
3032+
disable_csp,
3033+
enable_ws,
3034+
enable_sync,
3035+
use_auto_ext,
3036+
False, # Undetectable
3037+
uc_cdp_events,
3038+
uc_subprocess,
3039+
no_sandbox,
3040+
disable_gpu,
3041+
False, # headless2
3042+
incognito,
3043+
guest_mode,
3044+
dark_mode,
3045+
devtools,
3046+
remote_debug,
3047+
enable_3d_apis,
3048+
swiftshader,
3049+
ad_block_on,
3050+
block_images,
3051+
do_not_track,
3052+
chromium_arg,
3053+
user_data_dir,
3054+
extension_zip,
3055+
extension_dir,
3056+
binary_location,
3057+
driver_version,
3058+
page_load_strategy,
3059+
use_wire,
3060+
external_pdf,
3061+
servername,
3062+
mobile_emulator,
3063+
device_width,
3064+
device_height,
3065+
device_pixel_ratio,
3066+
)
3067+
if not path_chromedriver:
3068+
sb_install.main(
3069+
override="chromedriver %s"
3070+
% use_version,
3071+
intel_for_uc=False,
3072+
force_uc=False,
3073+
)
3074+
d_b_c = "--disable-build-check"
3075+
if os.path.exists(LOCAL_CHROMEDRIVER):
3076+
service = ChromeService(
3077+
executable_path=LOCAL_CHROMEDRIVER,
3078+
log_output=os.devnull,
3079+
service_args=[d_b_c],
3080+
)
3081+
driver = webdriver.Chrome(
3082+
service=service,
3083+
options=headless_options,
3084+
)
3085+
else:
3086+
service = ChromeService(
3087+
log_output=os.devnull,
3088+
service_args=[d_b_c],
3089+
)
3090+
driver = webdriver.Chrome(
3091+
service=service,
3092+
options=headless_options,
3093+
)
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+
)
3100+
driver.quit()
3101+
except Exception:
3102+
pass
30223103
try:
30233104
uc_path = None
30243105
if os.path.exists(LOCAL_UC_DRIVER):

seleniumbase/extensions/recorder.zip

0 Bytes
Binary file not shown.

seleniumbase/js_code/active_css_js.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
var selector = el.nodeName.toLowerCase();
1111
if (el.id) {
1212
elid = el.id;
13-
if (elid.includes(',') || elid.includes('.') || /\s/.test(elid) ||
14-
elid.includes('(') || elid.includes(')') || hasDigit(elid[0]))
13+
if (/\s/.test(elid) || elid.includes(',') || elid.includes('.') ||
14+
elid.includes('(') || elid.includes(':') || hasDigit(elid[0]))
1515
return cssPathByAttribute(el, 'id');
1616
selector += '#' + elid;
1717
path.unshift(selector);

seleniumbase/js_code/recorder_js.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
var selector = el.nodeName.toLowerCase();
1111
if (el.id) {
1212
elid = el.id;
13-
if (elid.includes(',') || elid.includes('.') || /\s/.test(elid) ||
14-
elid.includes('(') || elid.includes(')') || hasDigit(elid[0]))
13+
if (/\s/.test(elid) || elid.includes(',') || elid.includes('.') ||
14+
elid.includes('(') || elid.includes(':') || hasDigit(elid[0]))
1515
return cssPathByAttribute(el, 'id');
1616
selector += '#' + elid;
1717
path.unshift(selector);

seleniumbase/translate/translator.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,15 @@ def main():
620620
new_sb_lines.append(line1)
621621
new_sb_lines.append(line2)
622622
continue
623-
if line.count("(") == 1 and line.count(")") == 1:
623+
if (
624+
line.count("(") >= 1
625+
and line.count("(") == line.count(")")
626+
):
624627
whitespace = line_length2 - len(line.lstrip())
625628
new_ws = line[0:whitespace] + " "
626-
line1 = line.split("(")[0] + "("
627-
line2 = new_ws + line.split("(")[1]
629+
first_paren = line.find("(")
630+
line1 = line[:first_paren + 1]
631+
line2 = new_ws + line[first_paren + 1:]
628632
if not ("):") in line2:
629633
new_sb_lines.append(line1)
630634
if get_width(line2) + w > console_width:
@@ -722,9 +726,7 @@ def main():
722726
continue
723727
elif line2.count(", ") == 1:
724728
line2a = line2.split(", ")[0] + ","
725-
line2b = new_ws + (
726-
line2.split(", ")[1]
727-
)
729+
line2b = new_ws + line2.split(", ")[1]
728730
new_sb_lines.append(line2a)
729731
new_sb_lines.append(line2b)
730732
continue

seleniumbase/undetected/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def __init__(
132132
try:
133133
if hasattr(options, "_session") and options._session is not None:
134134
# Prevent reuse of options
135-
raise RuntimeError("you cannot reuse the ChromeOptions object")
135+
raise RuntimeError("You cannot reuse the ChromeOptions object")
136136
except AttributeError:
137137
pass
138138
options._session = self
@@ -434,7 +434,7 @@ def start_session(self, capabilities=None):
434434

435435
def quit(self):
436436
try:
437-
logger.debug("Terminating the browser")
437+
logger.debug("Terminating the UC browser")
438438
os.kill(self.browser_pid, 15)
439439
except TimeoutError as e:
440440
logger.debug(e, exc_info=True)
@@ -445,7 +445,7 @@ def quit(self):
445445
self.service.stop()
446446
try:
447447
if self.reactor and isinstance(self.reactor, Reactor):
448-
logger.debug("Shutting down reactor")
448+
logger.debug("Shutting down Reactor")
449449
self.reactor.event.set()
450450
except Exception:
451451
pass
@@ -464,7 +464,7 @@ def quit(self):
464464
except (RuntimeError, OSError, PermissionError) as e:
465465
logger.debug(
466466
"When removing the temp profile, a %s occured: "
467-
"%s\nretrying..."
467+
"%s\nRetrying..."
468468
% (e.__class__.__name__, e)
469469
)
470470
else:
@@ -473,7 +473,7 @@ def quit(self):
473473
)
474474
break
475475
time.sleep(0.1)
476-
# Dereference patcher, so patcher can start cleaning up as well.
476+
# Dereference Patcher so that it can start cleaning up as well.
477477
# This must come last, otherwise it will throw "in use" errors.
478478
self.patcher = None
479479

seleniumbase/undetected/patcher.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def fetch_release_number(self):
122122
if self.version_main:
123123
path += "_%s" % self.version_main
124124
path = path.upper()
125-
logger.debug("getting release number from %s" % path)
125+
logger.debug("Getting release number from %s" % path)
126126
return urlopen(self.url_repo + path).read().decode()
127127

128128
def fetch_package(self):
@@ -133,12 +133,12 @@ def fetch_package(self):
133133
u = "%s/%s/%s" % (
134134
self.url_repo, self.version_full, self.zip_name
135135
)
136-
logger.debug("downloading from %s" % u)
136+
logger.debug("Downloading from %s" % u)
137137
return urlretrieve(u)[0]
138138

139139
def unzip_package(self, fp):
140140
""" :return: path to unpacked executable """
141-
logger.debug("unzipping %s" % fp)
141+
logger.debug("Unzipping %s" % fp)
142142
try:
143143
os.unlink(self.zip_path)
144144
except (FileNotFoundError, OSError):
@@ -285,14 +285,14 @@ def __del__(self):
285285
now = time.monotonic()
286286
if now - t > timeout:
287287
logger.debug(
288-
"could not unlink %s in time (%d seconds)"
288+
"Could not unlink %s in time (%d seconds)"
289289
% (self.executable_path, timeout)
290290
)
291291
break
292292
try:
293293
os.unlink(self.executable_path)
294294
logger.debug(
295-
"successfully unlinked %s"
295+
"Successfully unlinked %s"
296296
% self.executable_path
297297
)
298298
break

seleniumbase/undetected/reactor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ async def listen(self):
8181
if "invalid session id" in str(e):
8282
pass
8383
else:
84-
logger.debug("exception ignored : %s", e)
84+
logger.debug("Exception ignored: %s", e)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@
134134
'pip>=23.2.1',
135135
'packaging>=23.1',
136136
'setuptools>=68.0.0;python_version<"3.8"',
137-
'setuptools>=68.2.0;python_version>="3.8"',
137+
'setuptools>=68.2.2;python_version>="3.8"',
138138
'wheel>=0.41.2',
139139
'attrs>=23.1.0',
140140
"certifi>=2023.7.22",
141141
'filelock>=3.12.2;python_version<"3.8"',
142-
'filelock>=3.12.3;python_version>="3.8"',
142+
'filelock>=3.12.4;python_version>="3.8"',
143143
'platformdirs>=3.10.0',
144144
'parse>=1.19.1',
145145
'parse-type>=0.6.2',

0 commit comments

Comments
 (0)