-
Notifications
You must be signed in to change notification settings - Fork 55
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
Base64 string returned from ExecuteScriptAsync decode error and shorter than the original string #3555
Comments
Hi @evolcano, I'm trying to reproduce your scenario. It will help for investigating if a sample project can be provided. Will sync the update later. Thanks |
Thanks @ElyssaJyu ! This is the demo project ,which has two file: 2.frmGetImgFromWeb.cs Suggestion: ps: Demo code |
Hi @evolcano,
Hope this will unblock your work. Could you give some details why you would like to get Base64 encoded image data, then convert Base64 string to create the image? Thanks |
Thank you @ElyssaJyu ! In my scenario, I want to get the image data of any ON-LINE page which displayed in WebView embeded in WinForm, and do some process. The entire process should be silent and automatically, without any human-computer interaction. I could not find any other approch to do this, because DOM of web page is still cann't be accesse through WebView2. Yes, I'm still blocked. Would you please do some test using on-line URL(not local file) and give me some feedback? Or give some alternative method to get the data of image direct form WebView2? Thanks again. ps:
2.Base64 image data string get from WebView2 I have compared two string, only the beginning (iVBORw0KGgoAAAANSUhEUgAAA) and end (AAAABJRU5ErkJggg==) is the same , the middle part is totally different. I'm really confused. |
Hi @evolcano, I have tried to replace from I would guess when the image data isn't complete in the first navigation, due to async task. The data I got will convert to a white blank image, when testing. You can check HTMLImageElement: loading property test whether the image is loaded. After second navigation, the image shows, but the Base64 string is different comparing with that from web page. That might be because the image source directly from web page and the image source from html embedded in html are different. Also please try AddWebResourceRequestedFilter method and raise WebResourceResponseReceived event to get webcontent data . Thanks. |
@ElyssaJyu , you are really awsome! Have a nice weekend. Finally I got the image data according to your solution. Thanks a lot! And I noticed after webView_NavigationCompleted trigged, the "complete" status of image is "True", but the image data is also bad. It is still a mystery to me. |
Hi @evolcano, What does "bad" image data refer to? |
Closing as answered but feel free to reactivate if you have more questions. Thanks |
Description
I want to get image from web, so I call ExecuteScriptAsync to return the Base64 string encoded from image. The image data string changed in three steps:
(1)The original Base64 string is:
1 Original Base64 image data in WebView2.txt
(3)The string from ExecuteScriptAsync is:
2 Json from call ExecuteScriptAsync .txt
(3)The string after decode by JsonConvert.DeserializeObject().ToString() is:
3 Base64 after DeserializeObject of Json data from WebView2.txt
ERROR 1: The string return from ExecuteScriptAsync is too much shorter than the original one;
ERROR 2: The image from Convert.FromBase64String is totally BLACK
Version
SDK: Microsoft.NET.Sdk
Runtime: 1.0.1823.32
Framework: net6.0-windows
OS: win11
Repro Steps
The jpg saved from Image which convented form Base64 string:
Additional context
The text was updated successfully, but these errors were encountered: