VB.Net WebView2 how to copy image?
I use WebView2 on my VB.Net Window Form and have been tring to copy an image on a navigated website to clipboard and save the image as bitmap to local folder. I googled a lot for last three days but unfortunately can not find a right solution. Below is one of the codes I tried.
Private Sub Button1_Click() Handles Button1.Click WebView2.Navigate("https://www.microsoft.com/en-us/") End Sub Private Async Sub WebView2_NavigationCompleted() Handles WebView2.NavigationCompleted Await WebView2.CoreWebView2.ExecuteScriptAsync("document.querySelector('picture img.lazyloaded')[1].select();") Await WebView2.CoreWebView2.ExecuteScriptAsync("document.execCommand('copy');") Using bmp As Bitmap = DirectCast(Clipboard.GetDataObject().GetData(DataFormats.Bitmap), Bitmap) bmp.Save("C:\Users\Me\Downloads\test1.bmp") End Using End Sub
Because I do not know about javascript much, that may results in unsuccessful code. Anyhow I tried lots of code but still can not achieve to copy image displayed on WebView2. I would appreciate for your help. Other than ExecuteScriptAsync, bitmap (directly save in jpg etc) are very welcome. I only know that javascript is the only method to handle WebView2 so far.