Skip to content

Commit 1464e7f

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

2 files changed

Lines changed: 23 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: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import browsers
1717
import requests
18-
from requests import Response, RequestException
18+
from requests import RequestException, Response
1919
from selenium import webdriver
2020
from selenium.webdriver.chrome.options import Options
2121
from selenium.webdriver.chrome.service import Service
@@ -41,7 +41,15 @@
4141

4242
class ChromeDriverManager:
4343
def get_chrome_driver(self, path_to_cache_dir: str):
44-
chrome_version = self.get_chrome_version()
44+
for browser in browsers.browsers():
45+
print(f"html2print: browser {browser.browser_type}:") # noqa: T201
46+
print(f" - path {browser.path}") # noqa: T201
47+
print(f" - display_name {browser.display_name}") # noqa: T201
48+
print(f" - version {browser.version}:") # noqa: T201
49+
50+
chrome_browser_info = browsers.get("chrome")
51+
chrome_version = chrome_browser_info["version"]
52+
chrome_path = chrome_browser_info["path"]
4553

4654
# If Web Driver Manager cannot detect Chrome, it returns None.
4755
if chrome_version is None:
@@ -55,6 +63,9 @@ def get_chrome_driver(self, path_to_cache_dir: str):
5563
print( # noqa: T201
5664
f"html2print: Installed Chrome version: {chrome_version}"
5765
)
66+
print( # noqa: T201
67+
f"html2print: Installed Chrome path: {chrome_path}"
68+
)
5869

5970
system_map = {
6071
"Windows": "win32",
@@ -181,8 +192,9 @@ def send_http_get_request(url, params=None, **kwargs) -> Response:
181192
f"html2print: "
182193
f"failed to get response for URL: {url} with error: {last_error}"
183194
)
184-
raise RequestException(f"GET request failed after 3 attempts: {url}") from last_error
185-
195+
raise RequestException(
196+
f"html2print: GET request failed after 3 attempts: {url}"
197+
) from last_error
186198

187199
@staticmethod
188200
def get_chrome_version():
@@ -329,7 +341,12 @@ def create_webdriver(
329341
else:
330342
service = Service(path_to_chrome)
331343

344+
path_to_chrome_browser = ""
345+
path_to_chrome_browser = browsers.get("chrome")["path"]
346+
print(f"html2print: Chrome available at path: {path_to_chrome_browser}") # noqa: T201
347+
332348
webdriver_options = Options()
349+
webdriver_options.binary_location = path_to_chrome_browser
333350
webdriver_options.add_argument("start-maximized")
334351
webdriver_options.add_argument("disable-infobars")
335352
# Doesn't seem to be needed.
@@ -462,7 +479,7 @@ def main():
462479
if browsers.get("chrome") is not None:
463480
path_to_chrome_browser = browsers.get("chrome")["path"]
464481
print( # noqa: T201
465-
f"html2print: Chrome available at path:{path_to_chrome_browser}"
482+
f"html2print: Chrome available at path: {path_to_chrome_browser}"
466483
)
467484
sys.exit(0)
468485

0 commit comments

Comments
 (0)