Skip to content

Commit 4b0f3e8

Browse files
committed
html2print: minor cleanups on windows
- add entrypoint.sh to .gitattributes so that it keeps the line-endings (windows/docker)
1 parent 660ef53 commit 4b0f3e8

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
entrypoint.sh -text

html2print/html2print.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from time import sleep
1414
from typing import Dict, List, Optional
1515

16+
import browsers
1617
import requests
1718
from requests import Response
1819
from selenium import webdriver
@@ -332,7 +333,9 @@ def create_webdriver(
332333
# Doesn't seem to be needed.
333334
# webdriver_options.add_argument('--disable-gpu') # noqa: ERA001
334335
webdriver_options.add_argument("--disable-extensions")
335-
webdriver_options.add_argument("--headless=chrome")
336+
# Use --headless=new, as it seems to be more stable on Windows (available since Chrome 109).
337+
# see https://www.selenium.dev/blog/2023/headless-is-going-away/
338+
webdriver_options.add_argument("--headless=new")
336339
# FIXME: This is not nice but otherwise it does not work in Ubuntu 24-based Docker image.
337340
# https://github.com/SeleniumHQ/selenium/issues/15327#issuecomment-2689287561
338341
webdriver_options.add_argument("--no-sandbox")
@@ -447,10 +450,18 @@ def main():
447450
args.cache_dir if args.cache_dir is not None else DEFAULT_CACHE_DIR
448451
)
449452

450-
path_to_chrome = ChromeDriverManager().get_chrome_driver(
453+
path_to_chrome_driver = ChromeDriverManager().get_chrome_driver(
451454
path_to_cache_dir
452455
)
453-
print(f"html2print: ChromeDriver available at path: {path_to_chrome}") # noqa: T201
456+
print( # noqa: T201
457+
f"html2print: ChromeDriver available at path: {path_to_chrome_driver}"
458+
)
459+
460+
if browsers.get("chrome") is not None:
461+
path_to_chrome_browser = browsers.get("chrome")["path"]
462+
print( # noqa: T201
463+
f"html2print: Chrome available at path:{path_to_chrome_browser}"
464+
)
454465
sys.exit(0)
455466

456467
elif args.command == "print":

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ dependencies = [
5454

5555
# requests is used by HTML2PDF_HTTPClient.
5656
"requests",
57+
58+
# to detect the browers path (needed on windows)
59+
"pybrowsers",
5760
]
5861

5962
[project.optional-dependencies]

0 commit comments

Comments
 (0)