Skip to content

webdriver_options: switch to --headless=new #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions html2print/html2print.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,30 +311,40 @@ def create_webdriver(
) -> webdriver.Chrome:
print("html2print: creating ChromeDriver service.", flush=True) # noqa: T201

path_to_chrome: str
path_to_chrome_driver: str
if chromedriver_argument is None:
path_to_chrome = ChromeDriverManager().get_chrome_driver(
path_to_chrome_driver = ChromeDriverManager().get_chrome_driver(
path_to_cache_dir
)
else:
path_to_chrome = chromedriver_argument
print(f"html2print: ChromeDriver available at path: {path_to_chrome}") # noqa: T201
path_to_chrome_driver = chromedriver_argument
print( # noqa: T201
f"html2print: ChromeDriver available at path: {path_to_chrome_driver}"
)

if debug:
service = Service(
path_to_chrome, log_output=PATH_TO_CHROME_DRIVER_DEBUG_LOG
path_to_chrome_driver, log_output=PATH_TO_CHROME_DRIVER_DEBUG_LOG
)
else:
service = Service(path_to_chrome)
service = Service(path_to_chrome_driver)

webdriver_options = Options()
webdriver_options.add_argument("start-maximized")
webdriver_options.add_argument("disable-infobars")
# Doesn't seem to be needed.
# webdriver_options.add_argument('--disable-gpu') # noqa: ERA001
webdriver_options.add_argument("--disable-extensions")
webdriver_options.add_argument("--headless=chrome")
# FIXME: This is not nice but otherwise it does not work in Ubuntu 24-based Docker image.

# Use --headless=new, as it seems to be more stable on Windows (available since Chrome 109).
# see https://www.selenium.dev/blog/2023/headless-is-going-away/
webdriver_options.add_argument("--headless=new")

# Docker disables some syscalls that are required for Chrome's sandbox to work.
# https://stackoverflow.com/questions/68855734/how-to-setup-chrome-sandbox-on-docker-container
# We prefer isolation of the container over isolation of tabs within Chrome,
# and thus disable the sandbox.
# See also:
# https://github.com/SeleniumHQ/selenium/issues/15327#issuecomment-2689287561
webdriver_options.add_argument("--no-sandbox")

Expand Down