Skip to content

Commit e171d6c

Browse files
committed
Update html2print.py
1 parent 343b7f2 commit e171d6c

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

.github/workflows/ci-linux-ubuntu-latest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- name: Build HTML2PDF.js
4848
run: |
4949
invoke build
50-
50+
5151
- name: Run tests
5252
run: |
5353
invoke test

html2print/html2print.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import argparse
33
import atexit
44
import base64
5+
import logging
56
import os.path
67
import platform
78
import re
@@ -15,12 +16,14 @@
1516

1617
import browsers
1718
import requests
18-
from requests import Response, RequestException
19+
from requests import RequestException, Response
1920
from selenium import webdriver
2021
from selenium.webdriver.chrome.options import Options
2122
from selenium.webdriver.chrome.service import Service
2223
from webdriver_manager.core.os_manager import ChromeType, OperationSystemManager
2324

25+
logging.basicConfig(level=logging.DEBUG)
26+
2427
__version__ = "0.0.15"
2528

2629
PATH_TO_HTML2PDF_JS = os.path.join(
@@ -41,7 +44,15 @@
4144

4245
class ChromeDriverManager:
4346
def get_chrome_driver(self, path_to_cache_dir: str):
44-
chrome_version = self.get_chrome_version()
47+
for browser in browsers.browsers():
48+
print(f"html2print: browser {browser['browser_type']}:") # noqa: T201
49+
print(f" - path {browser['path']}") # noqa: T201
50+
print(f" - display_name {browser['display_name']}") # noqa: T201
51+
print(f" - version {browser['version']}:") # noqa: T201
52+
53+
chrome_browser_info = browsers.get("chrome")
54+
chrome_version = chrome_browser_info["version"]
55+
chrome_path = chrome_browser_info["path"]
4556

4657
# If Web Driver Manager cannot detect Chrome, it returns None.
4758
if chrome_version is None:
@@ -55,6 +66,9 @@ def get_chrome_driver(self, path_to_cache_dir: str):
5566
print( # noqa: T201
5667
f"html2print: Installed Chrome version: {chrome_version}"
5768
)
69+
print( # noqa: T201
70+
f"html2print: Installed Chrome path: {chrome_path}"
71+
)
5872

5973
system_map = {
6074
"Windows": "win32",
@@ -181,8 +195,9 @@ def send_http_get_request(url, params=None, **kwargs) -> Response:
181195
f"html2print: "
182196
f"failed to get response for URL: {url} with error: {last_error}"
183197
)
184-
raise RequestException(f"GET request failed after 3 attempts: {url}") from last_error
185-
198+
raise RequestException(
199+
f"html2print: GET request failed after 3 attempts: {url}"
200+
) from last_error
186201

187202
@staticmethod
188203
def get_chrome_version():
@@ -329,7 +344,12 @@ def create_webdriver(
329344
else:
330345
service = Service(path_to_chrome)
331346

347+
path_to_chrome_browser = ""
348+
path_to_chrome_browser = browsers.get("chrome")["path"]
349+
print(f"html2print: Chrome available at path: {path_to_chrome_browser}") # noqa: T201
350+
332351
webdriver_options = Options()
352+
webdriver_options.binary_location = path_to_chrome_browser
333353
webdriver_options.add_argument("start-maximized")
334354
webdriver_options.add_argument("disable-infobars")
335355
# Doesn't seem to be needed.
@@ -462,7 +482,7 @@ def main():
462482
if browsers.get("chrome") is not None:
463483
path_to_chrome_browser = browsers.get("chrome")["path"]
464484
print( # noqa: T201
465-
f"html2print: Chrome available at path:{path_to_chrome_browser}"
485+
f"html2print: Chrome available at path: {path_to_chrome_browser}"
466486
)
467487
sys.exit(0)
468488

0 commit comments

Comments
 (0)