Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpage screenshots #70

Closed
sciguy16 opened this issue Feb 23, 2021 · 8 comments
Closed

Webpage screenshots #70

sciguy16 opened this issue Feb 23, 2021 · 8 comments

Comments

@sciguy16
Copy link

sciguy16 commented Feb 23, 2021

Is your feature request related to a problem? Please describe.
I think it would be useful to be able to capture screenshots of the rendered document/webpage, for example to programmatically screenshot web servers of as part of automated testing.

Stretch goal: potentially build a viable replacement for phantomjs, but that's probably not in scope for this issue.

Describe the solution you'd like
Ideally, some way to read the rendered framebuffer into a Vec of pixels so that it can be processed/encoded as PNG/etc.

Describe alternatives you've considered
In theory it should be possible to achieve this by injecting a copy of html2canvas into the page and then somehow getting the captured image back out of the webview, but some method for directly reading the rendered page would be cleaner (and more performant).

Would you assign yourself to implement this feature?

  • Yes - if it turns out to be relatively simple
  • No - if it requires major changes to Wry as I'm not familiar with the codebase

Additional context
Add any other context or screenshots about the feature request here.

@nothingismagick
Copy link
Member

Thanks for the idea. I am pinging @tensor-programming because he has been working on how to rig Tauri for testing purposes, and the domain seems similar.

@nothingismagick
Copy link
Member

It might be worthwhile to look into how tools like cypress and webdriver.io do screencaptures.

@sciguy16
Copy link
Author

I've created an example using html2canvas to capture webpages as png, but it doesn't work for all sites (probably origin issues as you suggested on discord): https://github.com/sciguy16/wry-screenshot

@nklayman
Copy link
Member

@nothingismagick
Copy link
Member

So, taking this one step further, could we use something like this to send that PNG to a PDF (and kill two flies with one swat):

This uses printpdf under the hood: https://github.com/Quantaly/jpeg-to-pdf/blob/main/Cargo.toml

@nklayman
Copy link
Member

nklayman commented Mar 9, 2021

The problem with that is it would only have the content shown in the viewport, not the whole page, right?.

@nothingismagick
Copy link
Member

Look what I just found (thanks @lucasfernog )
https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitSnapshotRegion

enum WebKitSnapshotRegion
Enum values used to specify the region from which to get a WebKitWebView snapshot

Members
WEBKIT_SNAPSHOT_REGION_VISIBLE
  Specifies a snapshot only for the area that is visible in the webview

WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT
  A snapshot of the entire document.

@nothingismagick
Copy link
Member

Please see #236 - this resolves for ALL platforms and creates proper PDF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants