html2image
html2image copied to clipboard
Browser executable check fails on RHEL for chromium-headless
I am using a Red Hat Enterprise Linux machine (version 8.3) with Python 3.6.8 and the current version of html2image.
On this distribution, several choices are presented when we want to install Chromium on it :
chromium.x86_64 96.0.4664.110-2.el8 epel
chromium-common.x86_64 96.0.4664.110-2.el8 epel
chromium-headless.x86_64 96.0.4664.110-2.el8 epel
I went for the last option since it looked the most convenient for our use case.
Instead of the usual Chromium package which install the full browser with its standard executable, this package installs only a Chromium "headless shell", located in /usr/lib64/chromium-browser/headless_shell
The issue I have is that, unlike the classic Chromium versions, this executable fails the executable check in html2image:
>>> from html2image import Html2Image
>>> hti = Html2Image(browser_executable='/usr/lib64/chromium-browser/headless_shell', custom_flags=['--headless', '--disable-gpu', '--disable-software-rasterizer', '--default-background-color=ffffffff'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/html2image/html2image.py", line 86, in __init__
flags=custom_flags,
File "/usr/local/lib/python3.6/site-packages/html2image/browsers/chrome.py", line 187, in __init__
self.executable = executable
File "/usr/local/lib/python3.6/site-packages/html2image/browsers/chrome.py", line 204, in executable
self._executable = _find_chrome(value)
File "/usr/local/lib/python3.6/site-packages/html2image/browsers/chrome.py", line 94, in _find_chrome
'Failed to find a seemingly valid chrome executable '
FileNotFoundError: Failed to find a seemingly valid chrome executable in the given path.
This is because /usr/lib64/chromium-browser/headless_shell --version
apparently does not give the Chromium version as expected.
It should be noted that, if I bypass the check by commenting it, everything works fine except that (I am able to make "screenshots" of pages normally).
I am unsure how this issue could be correctly fixed, maybe a special flag or condition could be implemented.
Hello, thank you for opening an issue.
Edit : I don't know why I didn't thought of it right away, but the more practical way would be to change the value of the browser's _executable
attribute :
>>> from html2image import Html2Image
>>> hti = Html2Image()
>>> hti.browser
<html2image.browsers.chrome.ChromeHeadless object at 0x000001896B3A9490>
>>> hti.browser._executable
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
>>> hti.browser._executable = YOUR_NEW_EXECUTABLE_PATH
Other method that should still work:
A way to temporarily solve your problem would be to set the HTML2IMAGE_TOGGLE_ENV_VAR_LOOKUP
environment variable to any value (example : true
), and set an environment variable with any of the following names :
- HTML2IMAGE_CHROME_BIN
- HTML2IMAGE_CHROME_EXE
- CHROME_BIN
- CHROME_EXE
to the path of your Chromium executable. Html2image iterates over these environment variable names in the same order as they are listed above. If CHROME_BIN
is already set on your system but you wish not to keep its content and not use it, you can set HTML2IMAGE_CHROME_BIN
for example.
Although this feature has yet to be documented and tested, it should do the trick, as the path provided using this method are not subject to any tests.
Regarding a fix, an argument could indeed be added the Html2Image class' __init__()
, for instance.