I have a WinForms2 C# application with a basic WebView2 component along with a textBox (to be used as a search bar). I want to restrict the webView2 from being able to download content. For example, if I go to pixabay.com and try to download an image, I want it to stop the download and restrict that image from being downloaded.
I tried using the CloseDefaultDownloadDialog and webView.CoreWebView2.IsDefaultDownloadDialogOpenChanged methods to block the content from downloading:
webView.CoreWebView2.IsDefaultDownloadDialogOpenChanged += downloadsPrompted;
and this:
private void downloadsPrompted(object sender, object e)
{
button1.Text = "It runs";
WebView2 webView = sender as WebView2;
if (webView.CoreWebView2.IsDefaultDownloadDialogOpen)
{
webView.CoreWebView2.CloseDefaultDownloadDialog();
}
}
However this didn’t work and the image still downloaded. I have the button1.Text = “It runs”; to make sure that method is actually running (and it ran).