Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

TakeSnapshot

Post Reply
brche
Posts: 16
Joined: Tue Feb 08, 2022 10:29 pm

TakeSnapshot

Post by brche »

Not a big problem; but your procedure to take a Snapshot in the MiniBrowser demo is named akeSnapShot. I think it should be TakeSnapShot

Brian
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TakeSnapshot

Post by salvadordf »

Fixed a couple of typos in that demo. Thanks!
brche
Posts: 16
Joined: Tue Feb 08, 2022 10:29 pm

Re: TakeSnapshot

Post by brche »

I noticed that you are using uWVBrowser.CapturePreview, instead of uWVWindowParent.TakeSnapshot. Is there a difference?

Thanks
Brian
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TakeSnapshot

Post by salvadordf »

TakeSnapshot is an old function copied from CEF4Delphi that doesn't work with WebView2.
It uses BitBlt and I'll remove it in the next update.
brche
Posts: 16
Joined: Tue Feb 08, 2022 10:29 pm

Re: TakeSnapshot

Post by brche »

It looks like CapturePreview does not work when the browser (or Window Parent?) is hidden.
We hide the form and take snapshots of the browser to display to the user. This does not seem to work when the form is hidden.

Brian
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TakeSnapshot

Post by salvadordf »

This seems to be an upstream issue in WebView2.

Try using the Page.captureScreenshot DevTools method :
https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-captureScreenshot

The MiniBrowser demo of the CEF4Delphi project uses it here :
https://github.com/salvadordf/CEF4Delphi/blob/03f9e9a1b9860ece476e1c9f667937d53370008d/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L1288
https://github.com/salvadordf/CEF4Delphi/blob/03f9e9a1b9860ece476e1c9f667937d53370008d/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L1370

Calling devtools methods in WebView4Delphi is very similar but you will have to use a JSON parser to get the result data and then use TNetEncoding.Base64.DecodeStringToBytes to decode it.

You may also report this CapturePreview issue in the official WebView2 Feedback repository :
https://github.com/MicrosoftEdge/WebView2Feedback
brche
Posts: 16
Joined: Tue Feb 08, 2022 10:29 pm

Re: TakeSnapshot

Post by brche »

Thanks,
It looks like is has already been reported:
https://github.com/MicrosoftEdge/WebView2Feedback/issues/579

Brian
brche
Posts: 16
Joined: Tue Feb 08, 2022 10:29 pm

Re: TakeSnapshot

Post by brche »

salvadordf wrote: Wed Feb 23, 2022 6:05 pm This seems to be an upstream issue in WebView2.

Try using the Page.captureScreenshot DevTools method :
https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-captureScreenshot

The MiniBrowser demo of the CEF4Delphi project uses it here :
https://github.com/salvadordf/CEF4Delphi/blob/03f9e9a1b9860ece476e1c9f667937d53370008d/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L1288
https://github.com/salvadordf/CEF4Delphi/blob/03f9e9a1b9860ece476e1c9f667937d53370008d/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L1370

Calling devtools methods in WebView4Delphi is very similar but you will have to use a JSON parser to get the result data and then use TNetEncoding.Base64.DecodeStringToBytes to decode it.

You may also report this CapturePreview issue in the official WebView2 Feedback repository :
https://github.com/MicrosoftEdge/WebView2Feedback
It looks like Devtools Page.captureScreenshot has the same problem.

Brian
brche
Posts: 16
Joined: Tue Feb 08, 2022 10:29 pm

Re: TakeSnapshot

Post by brche »

brche wrote: Wed Feb 23, 2022 9:53 pm
salvadordf wrote: Wed Feb 23, 2022 6:05 pm This seems to be an upstream issue in WebView2.

Try using the Page.captureScreenshot DevTools method :
https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-captureScreenshot

The MiniBrowser demo of the CEF4Delphi project uses it here :
https://github.com/salvadordf/CEF4Delphi/blob/03f9e9a1b9860ece476e1c9f667937d53370008d/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L1288
https://github.com/salvadordf/CEF4Delphi/blob/03f9e9a1b9860ece476e1c9f667937d53370008d/demos/Delphi_VCL/MiniBrowser/uMiniBrowser.pas#L1370

Calling devtools methods in WebView4Delphi is very similar but you will have to use a JSON parser to get the result data and then use TNetEncoding.Base64.DecodeStringToBytes to decode it.

You may also report this CapturePreview issue in the official WebView2 Feedback repository :
https://github.com/MicrosoftEdge/WebView2Feedback
It looks like Devtools Page.captureScreenshot has the same problem.

Brian
Do you have any ideas on how to make this work; or am I going to have to start using CEF4Delphi instead?

Brian
User avatar
salvadordf
Posts: 4079
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TakeSnapshot

Post by salvadordf »

I haven't checked these methods but I would also try :
  • Moving the TWVWindowParent control to a position outside the screen like (-1000, -1000) instead of setting the visibility to false.
  • Using JavaScript to take screenshots : https://stackoverflow.com/questions/42828187/how-to-take-a-screenshot-in-html-with-javascript
  • Using the WindowlessBrowser demo and modify TWVDirectCompositionHost.UpdateSize to move the visual to (-1000, -1000) or set a clipping rect with zero width and height instead of setting the visibility to false.
If all these points fail and you can't wait until the WebView2 project fixes this issue then you can move to CEF4Delphi.
Post Reply