Skip to content

Commit 1912fc7

Browse files
committed
webdriver_options: add explicit binary path on Windows, set --headless=new
1 parent 84481a9 commit 1912fc7

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

html2print/html2print.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,27 @@ def create_webdriver(
328328
service = Service(path_to_chrome)
329329

330330
webdriver_options = Options()
331+
332+
# Workaround for Windows: Chrome is not typically found in the PATH, so
333+
# need to supply the exact binary location manually.
334+
if platform.system() == "Windows":
335+
webdriver_options.binary_location = path_to_chrome
336+
331337
webdriver_options.add_argument("start-maximized")
332338
webdriver_options.add_argument("disable-infobars")
333339
# Doesn't seem to be needed.
334340
# webdriver_options.add_argument('--disable-gpu') # noqa: ERA001
335341
webdriver_options.add_argument("--disable-extensions")
336-
webdriver_options.add_argument("--headless=chrome")
337-
# FIXME: This is not nice but otherwise it does not work in Ubuntu 24-based Docker image.
342+
343+
# Use --headless=new, as it seems to be more stable on Windows (available since Chrome 109).
344+
# see https://www.selenium.dev/blog/2023/headless-is-going-away/
345+
webdriver_options.add_argument("--headless=new")
346+
347+
# Docker disables some syscalls that are required for Chrome's sandbox to work.
348+
# https://stackoverflow.com/questions/68855734/how-to-setup-chrome-sandbox-on-docker-container
349+
# We prefer isolation of the container over isolation of tabs within Chrome,
350+
# and thus disable the sandbox.
351+
# See also:
338352
# https://github.com/SeleniumHQ/selenium/issues/15327#issuecomment-2689287561
339353
webdriver_options.add_argument("--no-sandbox")
340354

0 commit comments

Comments
 (0)