mirror of
https://github.com/FlareSolverr/FlareSolverr.git
synced 2025-06-08 12:35:30 +00:00
Apply undetected-chromedriver patches
* Hide Chrome window in Windows/NT * Not use subprocess by default (independent process) * Kill Chromium processes properly to avoid defunct/zombie processes
This commit is contained in:
parent
e163019f28
commit
410ee7981f
@ -120,9 +120,10 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
|||||||
version_main=None,
|
version_main=None,
|
||||||
patcher_force_close=False,
|
patcher_force_close=False,
|
||||||
suppress_welcome=True,
|
suppress_welcome=True,
|
||||||
use_subprocess=True,
|
use_subprocess=False,
|
||||||
debug=False,
|
debug=False,
|
||||||
no_sandbox=True,
|
no_sandbox=True,
|
||||||
|
windows_headless=False,
|
||||||
**kw,
|
**kw,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@ -403,17 +404,21 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
|||||||
if not desired_capabilities:
|
if not desired_capabilities:
|
||||||
desired_capabilities = options.to_capabilities()
|
desired_capabilities = options.to_capabilities()
|
||||||
|
|
||||||
if not use_subprocess:
|
if not use_subprocess and not windows_headless:
|
||||||
self.browser_pid = start_detached(
|
self.browser_pid = start_detached(
|
||||||
options.binary_location, *options.arguments
|
options.binary_location, *options.arguments
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
startupinfo = subprocess.STARTUPINFO()
|
||||||
|
if os.name == 'nt' and windows_headless:
|
||||||
|
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||||
browser = subprocess.Popen(
|
browser = subprocess.Popen(
|
||||||
[options.binary_location, *options.arguments],
|
[options.binary_location, *options.arguments],
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
close_fds=IS_POSIX,
|
close_fds=IS_POSIX,
|
||||||
|
startupinfo=startupinfo
|
||||||
)
|
)
|
||||||
self.browser_pid = browser.pid
|
self.browser_pid = browser.pid
|
||||||
|
|
||||||
@ -698,6 +703,7 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
|||||||
def quit(self):
|
def quit(self):
|
||||||
try:
|
try:
|
||||||
self.service.process.kill()
|
self.service.process.kill()
|
||||||
|
self.service.process.wait(5)
|
||||||
logger.debug("webdriver process ended")
|
logger.debug("webdriver process ended")
|
||||||
except (AttributeError, RuntimeError, OSError):
|
except (AttributeError, RuntimeError, OSError):
|
||||||
pass
|
pass
|
||||||
|
@ -27,12 +27,14 @@ def start_detached(executable, *args):
|
|||||||
reader, writer = multiprocessing.Pipe(False)
|
reader, writer = multiprocessing.Pipe(False)
|
||||||
|
|
||||||
# do not keep reference
|
# do not keep reference
|
||||||
multiprocessing.Process(
|
process = multiprocessing.Process(
|
||||||
target=_start_detached,
|
target=_start_detached,
|
||||||
args=(executable, *args),
|
args=(executable, *args),
|
||||||
kwargs={"writer": writer},
|
kwargs={"writer": writer},
|
||||||
daemon=True,
|
daemon=True,
|
||||||
).start()
|
)
|
||||||
|
process.start()
|
||||||
|
process.join()
|
||||||
# receive pid from pipe
|
# receive pid from pipe
|
||||||
pid = reader.recv()
|
pid = reader.recv()
|
||||||
REGISTERED.append(pid)
|
REGISTERED.append(pid)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user