Skip to content

Commit

Permalink
Merge pull request #2109 from seleniumbase/update-recorder-uc-mode-an…
Browse files Browse the repository at this point in the history
…d-print

Update Recorder Mode, UC Mode, and Smart Word-Wrap
  • Loading branch information
mdmintz authored Sep 13, 2023
2 parents 2df116d + 2b74696 commit 121aade
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 49 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pip>=23.2.1
packaging>=23.1
setuptools>=68.0.0;python_version<"3.8"
setuptools>=68.2.0;python_version>="3.8"
setuptools>=68.2.2;python_version>="3.8"
wheel>=0.41.2
attrs>=23.1.0
certifi>=2023.7.22
filelock>=3.12.2;python_version<"3.8"
filelock>=3.12.3;python_version>="3.8"
filelock>=3.12.4;python_version>="3.8"
platformdirs>=3.10.0
parse>=1.19.1
parse-type>=0.6.2
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.18.5"
__version__ = "4.18.6"
14 changes: 8 additions & 6 deletions seleniumbase/console_scripts/sb_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,15 @@ def main():
new_sb_lines.append(line1)
new_sb_lines.append(line2)
continue
if line.count("(") == 1 and line.count(")") == 1:
if (
line.count("(") >= 1
and line.count("(") == line.count(")")
):
whitespace = line_length2 - len(line.lstrip())
new_ws = line[0:whitespace] + " "
line1 = line.split("(")[0] + "("
line2 = new_ws + line.split("(")[1]
first_paren = line.find("(")
line1 = line[:first_paren + 1]
line2 = new_ws + line[first_paren + 1:]
if not ("):") in line2:
new_sb_lines.append(line1)
if get_width(line2) + w > console_width:
Expand Down Expand Up @@ -302,9 +306,7 @@ def main():
continue
elif line2.count(", ") == 1:
line2a = line2.split(", ")[0] + ","
line2b = new_ws + (
line2.split(", ")[1]
)
line2b = new_ws + line2.split(", ")[1]
new_sb_lines.append(line2a)
new_sb_lines.append(line2b)
continue
Expand Down
115 changes: 98 additions & 17 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,11 +666,9 @@ def _set_chrome_options(
chrome_options = webdriver.ChromeOptions()
if is_using_uc(undetectable, browser_name):
from seleniumbase import undetected

chrome_options = undetected.ChromeOptions()
elif browser_name == constants.Browser.EDGE:
chrome_options = webdriver.edge.options.Options()

prefs = {}
prefs["download.default_directory"] = downloads_path
prefs["local_discovery.notifications_enabled"] = False
Expand Down Expand Up @@ -2485,12 +2483,12 @@ def get_local_driver(
binary_location = binary_loc
if binary_location:
edge_options.binary_location = binary_location
service = EdgeService(
executable_path=LOCAL_EDGEDRIVER,
log_output=os.devnull,
service_args=["--disable-build-check"],
)
try:
service = EdgeService(
executable_path=LOCAL_EDGEDRIVER,
log_output=os.devnull,
service_args=["--disable-build-check"],
)
driver = Edge(service=service, options=edge_options)
except Exception as e:
if not hasattr(e, "msg"):
Expand All @@ -2512,11 +2510,6 @@ def get_local_driver(
"only supports MSEdge version "
)[1].split(" ")[0]
elif "DevToolsActivePort file doesn't exist" in e.msg:
service = EdgeService(
executable_path=LOCAL_EDGEDRIVER,
log_output=os.devnull,
service_args=["--disable-build-check"],
)
# https://stackoverflow.com/a/56638103/7058266
args = " ".join(sys.argv)
free_port = 9222
Expand Down Expand Up @@ -2550,11 +2543,6 @@ def get_local_driver(
_mark_driver_repaired()
except Exception:
pass
service = EdgeService(
executable_path=LOCAL_EDGEDRIVER,
log_output=os.devnull,
service_args=["--disable-build-check"],
)
driver = Edge(service=service, options=edge_options)
return extend_driver(driver)
elif browser_name == constants.Browser.SAFARI:
Expand Down Expand Up @@ -3019,6 +3007,99 @@ def get_local_driver(
chrome_options.add_experimental_option(
"w3c", True
)
try:
if (
uc_chrome_version
and uc_chrome_version >= 117
and (headless or headless2)
and not user_agent
):
headless_options = _set_chrome_options(
browser_name,
downloads_path,
True, # headless
locale_code,
proxy_string,
proxy_auth,
proxy_user,
proxy_pass,
proxy_bypass_list,
proxy_pac_url,
multi_proxy,
user_agent,
recorder_ext,
disable_js,
disable_csp,
enable_ws,
enable_sync,
use_auto_ext,
False, # Undetectable
uc_cdp_events,
uc_subprocess,
no_sandbox,
disable_gpu,
False, # headless2
incognito,
guest_mode,
dark_mode,
devtools,
remote_debug,
enable_3d_apis,
swiftshader,
ad_block_on,
block_images,
do_not_track,
chromium_arg,
user_data_dir,
extension_zip,
extension_dir,
binary_location,
driver_version,
page_load_strategy,
use_wire,
external_pdf,
servername,
mobile_emulator,
device_width,
device_height,
device_pixel_ratio,
)
if not path_chromedriver:
sb_install.main(
override="chromedriver %s"
% use_version,
intel_for_uc=False,
force_uc=False,
)
d_b_c = "--disable-build-check"
if os.path.exists(LOCAL_CHROMEDRIVER):
service = ChromeService(
executable_path=LOCAL_CHROMEDRIVER,
log_output=os.devnull,
service_args=[d_b_c],
)
driver = webdriver.Chrome(
service=service,
options=headless_options,
)
else:
service = ChromeService(
log_output=os.devnull,
service_args=[d_b_c],
)
driver = webdriver.Chrome(
service=service,
options=headless_options,
)
user_agent = driver.execute_script(
"return navigator.userAgent;"
).replace("Headless", "")
chrome_options.add_argument(
"--user-agent=%s" % user_agent
)
driver.quit()
except Exception:
pass
try:
uc_path = None
if os.path.exists(LOCAL_UC_DRIVER):
Expand Down
Binary file modified seleniumbase/extensions/recorder.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions seleniumbase/js_code/active_css_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
var selector = el.nodeName.toLowerCase();
if (el.id) {
elid = el.id;
if (elid.includes(',') || elid.includes('.') || /\s/.test(elid) ||
elid.includes('(') || elid.includes(')') || hasDigit(elid[0]))
if (/\s/.test(elid) || elid.includes(',') || elid.includes('.') ||
elid.includes('(') || elid.includes(':') || hasDigit(elid[0]))
return cssPathByAttribute(el, 'id');
selector += '#' + elid;
path.unshift(selector);
Expand Down
4 changes: 2 additions & 2 deletions seleniumbase/js_code/recorder_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
var selector = el.nodeName.toLowerCase();
if (el.id) {
elid = el.id;
if (elid.includes(',') || elid.includes('.') || /\s/.test(elid) ||
elid.includes('(') || elid.includes(')') || hasDigit(elid[0]))
if (/\s/.test(elid) || elid.includes(',') || elid.includes('.') ||
elid.includes('(') || elid.includes(':') || hasDigit(elid[0]))
return cssPathByAttribute(el, 'id');
selector += '#' + elid;
path.unshift(selector);
Expand Down
14 changes: 8 additions & 6 deletions seleniumbase/translate/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,11 +620,15 @@ def main():
new_sb_lines.append(line1)
new_sb_lines.append(line2)
continue
if line.count("(") == 1 and line.count(")") == 1:
if (
line.count("(") >= 1
and line.count("(") == line.count(")")
):
whitespace = line_length2 - len(line.lstrip())
new_ws = line[0:whitespace] + " "
line1 = line.split("(")[0] + "("
line2 = new_ws + line.split("(")[1]
first_paren = line.find("(")
line1 = line[:first_paren + 1]
line2 = new_ws + line[first_paren + 1:]
if not ("):") in line2:
new_sb_lines.append(line1)
if get_width(line2) + w > console_width:
Expand Down Expand Up @@ -722,9 +726,7 @@ def main():
continue
elif line2.count(", ") == 1:
line2a = line2.split(", ")[0] + ","
line2b = new_ws + (
line2.split(", ")[1]
)
line2b = new_ws + line2.split(", ")[1]
new_sb_lines.append(line2a)
new_sb_lines.append(line2b)
continue
Expand Down
10 changes: 5 additions & 5 deletions seleniumbase/undetected/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def __init__(
try:
if hasattr(options, "_session") and options._session is not None:
# Prevent reuse of options
raise RuntimeError("you cannot reuse the ChromeOptions object")
raise RuntimeError("You cannot reuse the ChromeOptions object")
except AttributeError:
pass
options._session = self
Expand Down Expand Up @@ -434,7 +434,7 @@ def start_session(self, capabilities=None):

def quit(self):
try:
logger.debug("Terminating the browser")
logger.debug("Terminating the UC browser")
os.kill(self.browser_pid, 15)
except TimeoutError as e:
logger.debug(e, exc_info=True)
Expand All @@ -445,7 +445,7 @@ def quit(self):
self.service.stop()
try:
if self.reactor and isinstance(self.reactor, Reactor):
logger.debug("Shutting down reactor")
logger.debug("Shutting down Reactor")
self.reactor.event.set()
except Exception:
pass
Expand All @@ -464,7 +464,7 @@ def quit(self):
except (RuntimeError, OSError, PermissionError) as e:
logger.debug(
"When removing the temp profile, a %s occured: "
"%s\nretrying..."
"%s\nRetrying..."
% (e.__class__.__name__, e)
)
else:
Expand All @@ -473,7 +473,7 @@ def quit(self):
)
break
time.sleep(0.1)
# Dereference patcher, so patcher can start cleaning up as well.
# Dereference Patcher so that it can start cleaning up as well.
# This must come last, otherwise it will throw "in use" errors.
self.patcher = None

Expand Down
10 changes: 5 additions & 5 deletions seleniumbase/undetected/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def fetch_release_number(self):
if self.version_main:
path += "_%s" % self.version_main
path = path.upper()
logger.debug("getting release number from %s" % path)
logger.debug("Getting release number from %s" % path)
return urlopen(self.url_repo + path).read().decode()

def fetch_package(self):
Expand All @@ -133,12 +133,12 @@ def fetch_package(self):
u = "%s/%s/%s" % (
self.url_repo, self.version_full, self.zip_name
)
logger.debug("downloading from %s" % u)
logger.debug("Downloading from %s" % u)
return urlretrieve(u)[0]

def unzip_package(self, fp):
""" :return: path to unpacked executable """
logger.debug("unzipping %s" % fp)
logger.debug("Unzipping %s" % fp)
try:
os.unlink(self.zip_path)
except (FileNotFoundError, OSError):
Expand Down Expand Up @@ -285,14 +285,14 @@ def __del__(self):
now = time.monotonic()
if now - t > timeout:
logger.debug(
"could not unlink %s in time (%d seconds)"
"Could not unlink %s in time (%d seconds)"
% (self.executable_path, timeout)
)
break
try:
os.unlink(self.executable_path)
logger.debug(
"successfully unlinked %s"
"Successfully unlinked %s"
% self.executable_path
)
break
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/undetected/reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ async def listen(self):
if "invalid session id" in str(e):
pass
else:
logger.debug("exception ignored : %s", e)
logger.debug("Exception ignored: %s", e)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@
'pip>=23.2.1',
'packaging>=23.1',
'setuptools>=68.0.0;python_version<"3.8"',
'setuptools>=68.2.0;python_version>="3.8"',
'setuptools>=68.2.2;python_version>="3.8"',
'wheel>=0.41.2',
'attrs>=23.1.0',
"certifi>=2023.7.22",
'filelock>=3.12.2;python_version<"3.8"',
'filelock>=3.12.3;python_version>="3.8"',
'filelock>=3.12.4;python_version>="3.8"',
'platformdirs>=3.10.0',
'parse>=1.19.1',
'parse-type>=0.6.2',
Expand Down

0 comments on commit 121aade

Please sign in to comment.