|
13 | 13 | from time import sleep |
14 | 14 | from typing import Dict, List, Optional |
15 | 15 |
|
| 16 | +import browsers |
16 | 17 | import requests |
17 | | -from requests import Response |
| 18 | +from requests import Response, RequestException |
18 | 19 | from selenium import webdriver |
19 | 20 | from selenium.webdriver.chrome.options import Options |
20 | 21 | from selenium.webdriver.chrome.service import Service |
@@ -180,6 +181,8 @@ def send_http_get_request(url, params=None, **kwargs) -> Response: |
180 | 181 | f"html2print: " |
181 | 182 | f"failed to get response for URL: {url} with error: {last_error}" |
182 | 183 | ) |
| 184 | + raise RequestException(f"GET request failed after 3 attempts: {url}") from last_error |
| 185 | + |
183 | 186 |
|
184 | 187 | @staticmethod |
185 | 188 | def get_chrome_version(): |
@@ -332,7 +335,9 @@ def create_webdriver( |
332 | 335 | # Doesn't seem to be needed. |
333 | 336 | # webdriver_options.add_argument('--disable-gpu') # noqa: ERA001 |
334 | 337 | webdriver_options.add_argument("--disable-extensions") |
335 | | - webdriver_options.add_argument("--headless=chrome") |
| 338 | + # Use --headless=new, as it seems to be more stable on Windows (available since Chrome 109). |
| 339 | + # see https://www.selenium.dev/blog/2023/headless-is-going-away/ |
| 340 | + webdriver_options.add_argument("--headless=new") |
336 | 341 | # FIXME: This is not nice but otherwise it does not work in Ubuntu 24-based Docker image. |
337 | 342 | # https://github.com/SeleniumHQ/selenium/issues/15327#issuecomment-2689287561 |
338 | 343 | webdriver_options.add_argument("--no-sandbox") |
@@ -447,10 +452,18 @@ def main(): |
447 | 452 | args.cache_dir if args.cache_dir is not None else DEFAULT_CACHE_DIR |
448 | 453 | ) |
449 | 454 |
|
450 | | - path_to_chrome = ChromeDriverManager().get_chrome_driver( |
| 455 | + path_to_chrome_driver = ChromeDriverManager().get_chrome_driver( |
451 | 456 | path_to_cache_dir |
452 | 457 | ) |
453 | | - print(f"html2print: ChromeDriver available at path: {path_to_chrome}") # noqa: T201 |
| 458 | + print( # noqa: T201 |
| 459 | + f"html2print: ChromeDriver available at path: {path_to_chrome_driver}" |
| 460 | + ) |
| 461 | + |
| 462 | + if browsers.get("chrome") is not None: |
| 463 | + path_to_chrome_browser = browsers.get("chrome")["path"] |
| 464 | + print( # noqa: T201 |
| 465 | + f"html2print: Chrome available at path:{path_to_chrome_browser}" |
| 466 | + ) |
454 | 467 | sys.exit(0) |
455 | 468 |
|
456 | 469 | elif args.command == "print": |
|
0 commit comments