PATCH WEDNESDAY
3.4.5 damn versioning **patch to fix headless mode** -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
0e27329b91
commit
6e471aaac2
|
@ -123,7 +123,6 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
||||||
use_subprocess=True,
|
use_subprocess=True,
|
||||||
debug=False,
|
debug=False,
|
||||||
no_sandbox=True,
|
no_sandbox=True,
|
||||||
|
|
||||||
**kw,
|
**kw,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
@ -287,9 +286,6 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
||||||
|
|
||||||
# see if a custom user profile is specified in options
|
# see if a custom user profile is specified in options
|
||||||
for arg in options.arguments:
|
for arg in options.arguments:
|
||||||
if any([_ in arg for _ in ('--headless', 'headless')]):
|
|
||||||
options.arguments.remove(arg)
|
|
||||||
options.headless = True
|
|
||||||
if "lang" in arg:
|
if "lang" in arg:
|
||||||
m = re.search("(?:--)?lang(?:[ =])?(.*)", arg)
|
m = re.search("(?:--)?lang(?:[ =])?(.*)", arg)
|
||||||
try:
|
try:
|
||||||
|
@ -358,7 +354,9 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
||||||
options.binary_location = (
|
options.binary_location = (
|
||||||
browser_executable_path or find_chrome_executable()
|
browser_executable_path or find_chrome_executable()
|
||||||
)
|
)
|
||||||
|
|
||||||
self._delay = 3
|
self._delay = 3
|
||||||
|
|
||||||
self.user_data_dir = user_data_dir
|
self.user_data_dir = user_data_dir
|
||||||
self.keep_user_data_dir = keep_user_data_dir
|
self.keep_user_data_dir = keep_user_data_dir
|
||||||
|
|
||||||
|
@ -367,16 +365,13 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
||||||
if no_sandbox:
|
if no_sandbox:
|
||||||
options.arguments.extend(["--no-sandbox", "--test-type"])
|
options.arguments.extend(["--no-sandbox", "--test-type"])
|
||||||
if headless or options.headless:
|
if headless or options.headless:
|
||||||
if self.patcher.version_main < 108:
|
options.headless = True
|
||||||
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("--window-size=1920,1080")
|
||||||
options.add_argument("--start-maximized")
|
options.add_argument("--start-maximized")
|
||||||
options.add_argument("--no-sandbox")
|
options.add_argument("--no-sandbox")
|
||||||
# fixes "could not connect to chrome" error when running
|
# fixes "could not connect to chrome" error when running
|
||||||
# on linux using privileged user like root (which i don't recommend)
|
# on linux using privileged user like root (which i don't recommend)
|
||||||
|
|
||||||
options.add_argument(
|
options.add_argument(
|
||||||
"--log-level=%d" % log_level
|
"--log-level=%d" % log_level
|
||||||
or divmod(logging.getLogger().getEffectiveLevel(), 10)[0]
|
or divmod(logging.getLogger().getEffectiveLevel(), 10)[0]
|
||||||
|
|
|
@ -48,8 +48,6 @@ class Patcher(object):
|
||||||
d = "~/.undetected_chromedriver"
|
d = "~/.undetected_chromedriver"
|
||||||
data_path = os.path.abspath(os.path.expanduser(d))
|
data_path = os.path.abspath(os.path.expanduser(d))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, executable_path=None, force=False, version_main: int = 0):
|
def __init__(self, executable_path=None, force=False, version_main: int = 0):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -63,13 +61,13 @@ class Patcher(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.force = force
|
self.force = force
|
||||||
self._custom_exe_path = False
|
|
||||||
prefix = "undetected"
|
prefix = "undetected"
|
||||||
|
|
||||||
if not os.path.exists(self.data_path):
|
if not os.path.exists(self.data_path):
|
||||||
os.makedirs(self.data_path, exist_ok=True)
|
os.makedirs(self.data_path, exist_ok=True)
|
||||||
|
|
||||||
|
self.executable_path = executable_path
|
||||||
if not executable_path:
|
if not executable_path:
|
||||||
self.executable_path = os.path.join(
|
self.executable_path = os.path.join(
|
||||||
self.data_path, "_".join([prefix, self.exe_name])
|
self.data_path, "_".join([prefix, self.exe_name])
|
||||||
|
@ -87,6 +85,8 @@ class Patcher(object):
|
||||||
os.path.join(".", self.executable_path)
|
os.path.join(".", self.executable_path)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._custom_exe_path = False
|
||||||
|
|
||||||
if executable_path:
|
if executable_path:
|
||||||
self._custom_exe_path = True
|
self._custom_exe_path = True
|
||||||
self.executable_path = executable_path
|
self.executable_path = executable_path
|
||||||
|
|
Loading…
Reference in New Issue