mirror of
https://github.com/FlareSolverr/FlareSolverr.git
synced 2025-06-08 12:35:30 +00:00
Add browser headless mode for Windows
This commit is contained in:
parent
93041779fb
commit
3b9fd0aa6a
@ -119,6 +119,7 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
|
|||||||
suppress_welcome=True,
|
suppress_welcome=True,
|
||||||
use_subprocess=False,
|
use_subprocess=False,
|
||||||
debug=False,
|
debug=False,
|
||||||
|
windows_headless=False,
|
||||||
**kw
|
**kw
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@ -384,17 +385,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
|
||||||
|
|
||||||
|
@ -43,8 +43,11 @@ def get_webdriver() -> WebDriver:
|
|||||||
|
|
||||||
# note: headless mode is detected (options.headless = True)
|
# note: headless mode is detected (options.headless = True)
|
||||||
# we launch the browser in head-full mode with the window hidden
|
# we launch the browser in head-full mode with the window hidden
|
||||||
|
windows_headless = False
|
||||||
if get_config_headless():
|
if get_config_headless():
|
||||||
if os.name != 'nt': # not in windows
|
if os.name == 'nt':
|
||||||
|
windows_headless = True
|
||||||
|
else:
|
||||||
start_xvfb_display()
|
start_xvfb_display()
|
||||||
|
|
||||||
# if we are inside the Docker container, we avoid downloading the driver
|
# if we are inside the Docker container, we avoid downloading the driver
|
||||||
@ -57,7 +60,8 @@ def get_webdriver() -> WebDriver:
|
|||||||
|
|
||||||
# downloads and patches the chromedriver
|
# downloads and patches the chromedriver
|
||||||
# todo: if we don't set driver_executable_path it downloads, patches, and deletes the driver each time
|
# todo: if we don't set driver_executable_path it downloads, patches, and deletes the driver each time
|
||||||
driver = uc.Chrome(options=options, driver_executable_path=driver_exe_path, version_main=version_main)
|
driver = uc.Chrome(options=options, driver_executable_path=driver_exe_path, version_main=version_main,
|
||||||
|
windows_headless=windows_headless)
|
||||||
|
|
||||||
# selenium vanilla
|
# selenium vanilla
|
||||||
# options = webdriver.ChromeOptions()
|
# options = webdriver.ChromeOptions()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user