3.4.5
damn versioning **patch to fix headless mode** currently headless undetected: https://i.imgur.com/CME9ElR.png (but still unsupported!) -https://stackoverflow.com/a/73840130/7058266 -https://support.google.com/chrome/a/answer/7679408#hdlssMod110 thanks @mdmintz for this info
This commit is contained in:
parent
6e471aaac2
commit
5b636cb768
|
@ -286,6 +286,11 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
|||
|
||||
# see if a custom user profile is specified in options
|
||||
for arg in options.arguments:
|
||||
|
||||
if any([_ in arg for _ in ("--headless", "headless")]):
|
||||
options.arguments.remove(arg)
|
||||
options.headless = True
|
||||
|
||||
if "lang" in arg:
|
||||
m = re.search("(?:--)?lang(?:[ =])?(.*)", arg)
|
||||
try:
|
||||
|
@ -364,13 +369,18 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
|||
options.arguments.extend(["--no-default-browser-check", "--no-first-run"])
|
||||
if no_sandbox:
|
||||
options.arguments.extend(["--no-sandbox", "--test-type"])
|
||||
|
||||
if headless or options.headless:
|
||||
options.headless = True
|
||||
options.add_argument("--window-size=1920,1080")
|
||||
options.add_argument("--start-maximized")
|
||||
options.add_argument("--no-sandbox")
|
||||
# fixes "could not connect to chrome" error when running
|
||||
# on linux using privileged user like root (which i don't recommend)
|
||||
if self.patcher.version_main < 108:
|
||||
options.add_argument("--headless=chrome")
|
||||
elif self.patcher.version_main >= 108:
|
||||
options.add_argument("--headless=new")
|
||||
|
||||
options.add_argument("--window-size=1920,1080")
|
||||
options.add_argument("--start-maximized")
|
||||
options.add_argument("--no-sandbox")
|
||||
# fixes "could not connect to chrome" error when running
|
||||
# on linux using privileged user like root (which i don't recommend)
|
||||
|
||||
options.add_argument(
|
||||
"--log-level=%d" % log_level
|
||||
|
|
|
@ -50,7 +50,6 @@ class Patcher(object):
|
|||
|
||||
def __init__(self, executable_path=None, force=False, version_main: int = 0):
|
||||
"""
|
||||
|
||||
Args:
|
||||
executable_path: None = automatic
|
||||
a full file path to the chromedriver executable
|
||||
|
@ -59,15 +58,13 @@ class Patcher(object):
|
|||
version_main: 0 = auto
|
||||
specify main chrome version (rounded, ex: 82)
|
||||
"""
|
||||
|
||||
self.force = force
|
||||
|
||||
self._custom_exe_path = False
|
||||
prefix = "undetected"
|
||||
|
||||
if not os.path.exists(self.data_path):
|
||||
os.makedirs(self.data_path, exist_ok=True)
|
||||
|
||||
self.executable_path = executable_path
|
||||
if not executable_path:
|
||||
self.executable_path = os.path.join(
|
||||
self.data_path, "_".join([prefix, self.exe_name])
|
||||
|
@ -85,8 +82,6 @@ class Patcher(object):
|
|||
os.path.join(".", self.executable_path)
|
||||
)
|
||||
|
||||
self._custom_exe_path = False
|
||||
|
||||
if executable_path:
|
||||
self._custom_exe_path = True
|
||||
self.executable_path = executable_path
|
||||
|
|
Loading…
Reference in New Issue