Closed saguileran closed 3 months ago
Hello,
It is not possible as-is, as browsers launched in headless mode directly generate an image file.
However, if you feel like tinkering, you may try to use html2image
with Chrome CDP like so:
from html2image import Html2Image
with Html2Image(browser='chrome-cdp') as hti:
my_base64_data = hti.screenshot(url='https://python.org', save_as='python_org.png')
But you'll have to modify the screenshot
method a tiny bit (locally, on your machine):
Instead of writing the base64 data to a file, you can just add a return img_data
instead.
Please note that Chrome CDP support is undocumented, on stand-by, and can sometimes break. If you're not familiar with the principle behind the Chrome DevTools Protocol, you can think of it as:
When using the with
context manager like so:
with Html2Image(browser='chrome-cdp') as hti:
...
A CDP server is opened behind the scenes, so if you want to take multiple screenshots, it is better to stay in the with
block to keep the server open and avoid the startup delay before every screenshot.
Hello.
Is it possible to make a screenshot without saving the image? I mean, get the image as base64