-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
A simple option that when enabled removes a lot of bloat from chrome where the goal is to reach a higher thread number where every less mb of consumption counts. Just getting it out there if it's doable, have seen a few people asking for reducing memory and cpu usage on high threads.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 5 comments 17 replies
-
Are you referring to pytest multithreading internals or Chrome internals? pytest
is a separate repo, and Chrome can be configured via various Selenium options available. Not everything about Chrome can be configured though.
Beta Was this translation helpful? Give feedback.
All reactions
-
Both, and my question was aswell where can I find the options for that?
Beta Was this translation helpful? Give feedback.
All reactions
-
pytest
has its own repo: https://github.com/pytest-dev/pytest (lots of command-line options).
It also has several plugins, such as pytest-xdist
(which provides the multithreading options):
https://github.com/pytest-dev/pytest-xdist
For a list of Chromium command-line options, see: https://peter.sh/experiments/chromium-command-line-switches/
SeleniumBase already uses many of them, and has its own args for enabling the ones that aren't enabled by default.
Use SeleniumBase's chromium_arg
to pass a list of comma-separated Chromium args if there's no direct arg for it.
Beta Was this translation helpful? Give feedback.
All reactions
-
pytest
has its own repo: https://github.com/pytest-dev/pytest (lots of command-line options). It also has several plugins, such aspytest-xdist
(which provides the multithreading options): https://github.com/pytest-dev/pytest-xdistFor a list of Chromium command-line options, see: https://peter.sh/experiments/chromium-command-line-switches/ SeleniumBase already uses many of them, and has its own args for enabling the ones that aren't enabled by default. Use SeleniumBase's
chromium_arg
to pass a list of comma-separated Chromium args if there's no direct arg for it.
Where can I find the list of the sb list of args?
Beta Was this translation helpful? Give feedback.
All reactions
-
The SeleniumBase pytest args are listed here: SeleniumBase/help_docs/customizing_test_runs.md
Beta Was this translation helpful? Give feedback.
All reactions
-
I meant for the raw driver
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
def Driver(
Got it, thanks! When I am using a pytest xdist do I select multi_proxy on the raw driver?
Beta Was this translation helpful? Give feedback.
All reactions
-
More info on using multiple proxies: #1832 (comment)
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Got it, thanks!
Quick question, for raw driver how do I change window height/width? I assume 'd_width=None, # Set device width
d_height=None, # Set device height
d_p_r=None, # Set device pixel ratio' are different and relating to different things? if so, what exactly?
Beta Was this translation helpful? Give feedback.
All reactions
-
Those are for mobile device metrics. (Something different, only for mobile
mode.)
You want this: driver.set_window_size(width, height)
(It is set after the browser is launched.)
Beta Was this translation helpful? Give feedback.
All reactions
-
Ah ok I see, where can I find the list of the '.sets' available for raw driver such as that one?
Beta Was this translation helpful? Give feedback.
All reactions
-
If it's already included with raw selenium
(eg. driver.set_window_size(width, height)
), then it won't be listed in the SeleniumBase Docs. (It's probably already somewhere in the Selenium Docs.)
But there is a section for driver
methods that were added in SeleniumBase: #2200 (comment)
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
In regards to the thread I meant if there was a way to actually remove things that weight the browser down or change the binary itself or something related but I assume that's creating a new browser?
Beta Was this translation helpful? Give feedback.
All reactions
-
I'm not sure what you mean by this. Chrome is what it is. There are options available so that you can customize Chrome. SeleniumBase provides command-line options and method args for making those customizations, as listed in the comments above.
Beta Was this translation helpful? Give feedback.
All reactions
-
I meant modify the Chromium source code itself then rebuild to be used with selenium base or is this just making it detectable and maybe a monkeypatch is better or?
Beta Was this translation helpful? Give feedback.
All reactions
-
"modify the Chromium source code"
I don't know anything about that. UC Mode modifies chromedriver (not Chrome / Chromium).
Most Chromium browsers are just modified versions of Chrome anyway (eg. Brave or Opera).
Beta Was this translation helpful? Give feedback.
All reactions
-
"modify the Chromium source code"
I don't know anything about that. UC Mode modifies chromedriver (not Chrome / Chromium). Most Chromium browsers are just modified versions of Chrome anyway (eg. Brave or Opera).
Yes that's what I meant, so one could technically modify the chromedriver directly and perform direct changes on it?
Beta Was this translation helpful? Give feedback.
All reactions
-
That's what undetected/patcher.py does.
Beta Was this translation helpful? Give feedback.
All reactions
-
Noted, just a quick question, how do you know here where to and what to patch if you have the time to do a quick walkthrough?
def patch_exe(self):
"""Patches the ChromeDriver binary"""
def gen_js_whitespaces(match):
return b"\n" * len(match.group())
def gen_call_function_js_cache_name(match):
rep_len = len(match.group()) - 3
ran_len = random.randint(6, rep_len)
bb = b"'" + bytes(str().join(random.choices(
population=string.ascii_letters, k=ran_len
)), 'ascii') + b"';" + (b"\n" * (rep_len - ran_len))
return bb
with io.open(self.executable_path, "r+b") as fh:
file_bin = fh.read()
file_bin = re.sub(
b"window\\.cdc_[a-zA-Z0-9]{22}_"
b"(Array|Promise|Symbol|Object|Proxy|JSON)"
b" = window\\.(Array|Promise|Symbol|Object|Proxy|JSON);",
gen_js_whitespaces,
file_bin,
)
file_bin = re.sub(
b"window\\.cdc_[a-zA-Z0-9]{22}_"
b"(Array|Promise|Symbol|Object|Proxy|JSON) \\|\\|",
gen_js_whitespaces,
file_bin,
)
file_bin = re.sub(
b"'\\$cdc_[a-zA-Z0-9]{22}_';",
gen_call_function_js_cache_name,
file_bin,
)
fh.seek(0)
fh.write(file_bin)
return True
Beta Was this translation helpful? Give feedback.
All reactions
-
You should ask the maintainer of undetected-chromedriver
.
It came from undetected_chromedriver/patcher.py
Beta Was this translation helpful? Give feedback.