vgalin / html2image

A package acting as a wrapper around the headless mode of existing web browsers to generate images from URLs and from HTML+CSS strings or files.
MIT License
354 stars 43 forks source link

Recent chromium versions experience errors on screenshot method #158

Closed jrb-github closed 1 month ago

jrb-github commented 2 months ago

Current (as of 2024-09-03) MS Edge versions fail on the screenshot method.

MS Edge 128.0.2739.54, if entering edge://version in the URL bar, reports it is Chromium 128.0.6613.114.

Using the screenshot method with this EXE silently fails.

When trying to track down a close chromium version, I found 128.0.6613.0, and it yields this:

>>> path_to_ms_edge = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
>>> hti = Html2Image(output_path=image_folder_path, browser_executable=path_to_ms_edge)
>>> hti.screenshot(url=html_file_path, size=(html_image_width, html_image_height))
[4864:5696:0903/154355.619:ERROR:sandbox_win.cc(852)] Sandbox cannot access executable. Check filesystem permissions are valid. See https://bit.ly/31yqMJR.: Access is denied. (0x5)
[4864:7440:0903/154355.728:ERROR:network_service_instance_impl.cc(608)] Network service crashed, restarting service.

A Chromium version 127.0.x.x that I tried did not exhibit this behavior.

Similar behavior persists through last night's nightly Chromium build 130.0.6697.0.

Strangely, when not specifying the browser_executable path, I don't see these problems. Installed Chrome is 128.0.6613.120, where I would expect to see the issue.


EDIT - I isolated this much further.

Using the binaries in this zip in this folder, the problem does not occur. With the binaries in this zip in this folder, it does. The problem was introduced on 2024-06-17, and just wasn't up-taken by MS Edge until last week or so.

Also, after the problem was introduced on 2024-06-17, both error lines shown above print, but the screenshot still generates in Chromium (though silently fails in MS Edge). Between then and 2024-09-03, only the first error line prints (Sandbox cannot access executable), then the screenshot method hangs.

git-n-pissed commented 1 month ago

@jrb-github, I'm seeing the same problem. I originally thought the issue was limited to Chrome because Edge was still working. Since I created #159, Edge has updated and now taking a screenshot is not possible with either browser.

fvarrui commented 1 month ago

Is there a way to use Firefox instead of a Chromium based browser on Windows?

git-n-pissed commented 1 month ago

Is there a way to use Firefox instead of Chromium based browsers on Windows?

I'm pretty sure html2image only works with Chromium based browsers. If this issue doesn't get fixed soon, people relying on html2image might consider embedding an older version of Chromium into their app as discussed here:

https://medium.com/free-code-camp/the-python-desktop-application-3a66b4a128d3

IDK if that would work for sure, but it is the best idea I have ATM.

fvarrui commented 1 month ago

I'm pretty sure html2image only works with Chromium based browsers.

😞

If this issue doesn't get fixed soon, people relying on html2image might consider embedding an older version of Chromium into their app as discussed here:

https://medium.com/free-code-camp/the-python-desktop-application-3a66b4a128d3

IDK if that would work for sure, but it is the best idea I have ATM.

Thanks so much for the suggestion and for your quick reply. I'll take a look! 👀

fvarrui commented 1 month ago

I've just embedded a Google Chrome 127.0.6533.120 from portableapps so I didn't have to downgrade Google Chrome on my dev machine (Windows), and then did this:

hti = Html2Image(browser_executable = 'GoogleChromePortable/GoogleChromePortable.exe')

It's not the best solution (300MB+ size) but at the moment it works for me. I hope it helps! Thanks @git-n-pissed

git-n-pissed commented 1 month ago

I've just embedded a Google Chrome 127.0.6533.120 from portableapps so I didn't have to downgrade Google Chrome on my dev machine (Windows), and then did this:

hti = Html2Image(browser_executable = 'GoogleChromePortable/GoogleChromePortable.exe')

It's not the best solution (300MB+ size) but at the moment it works for me. I hope it helps! Thanks @git-n-pissed

Good to know that is a viable workaround. Thanks for commenting back.

vgalin commented 1 month ago

A new version of html2image was released (v2.0.5), it should address this issue. Could you confirm that everything is working properly after updating the package? Thanks!

pip install --upgrade html2image
git-n-pissed commented 1 month ago

A new version of html2image was released (v2.0.5), it should address this issue. Could you confirm that everything is working properly after updating the package? Thanks!

pip install --upgrade html2image

Just updated and that seems to have fixed the issue. Thanks for the quick turn around on this @vgalin!

Do you know of any other breaking changes in the pipeline for Chromium? Just weighing the pros/cons of embedding a known compatible version of Chromium into my app.

jrb-github commented 1 month ago

2.0.5 works for me as well, thanks!

vgalin commented 1 month ago

Do you know of any other breaking changes in the pipeline for Chromium? Just weighing the pros/cons of embedding a known compatible version of Chromium into my app. Your message is generally well-written, but here are some minor adjustments to improve clarity and flow:

@git-n-pissed I don't personally know of any, but on the other hand, I'm not actively following upcoming changes. This breaking change was a "huge" one, as they made the headless version closer (if not identical) to the non-headless version. However, it could have been non-breaking for html2image if they had kept the --headless flag unchanged.

If your workflow relies heavily on html2image, keeping a portable version of Chromium might be the way to go.