One possible method to conceal the Download dialog box in WebView2 during the process of downloading page content or using the "Save as PDF" feature is to use the WebView2 Environment.Options object and set the silent printing and download options to true. This will enable the silent download and printing mode and hide the download dialog box.
For example:
var env = await CoreWebView2Environment.CreateAsync();
var options = new CoreWebView2EnvironmentOptions();
options.AdditionalBrowserArguments = "--silent-printing --disable-downloads";
env.CreateCoreWebView2Async(null, new SilentDownloadWebView2Handler());
public class SilentDownloadWebView2Handler : CoreWebView2CreateCoreWebView2EnvironmentCompletedHandler {
public override void CreateCoreWebView2EnvironmentCompleted(int result, CoreWebView2Environment env) {
var options = env.Options;
options.SilentPrintingEnabled = true;
options.IsStatusBarEnabled = false;
options.AreDefaultContextMenusEnabled = true;
options.AreDevToolsEnabled = false;
options.IsZoomControlEnabled = false;
options.DownloadStarting += (sender, e) => e.Cancel = true;
base.CreateCoreWebView2EnvironmentCompleted(result, env);
}
}
This code will create a WebView2 environment with the silent printing and download options enabled, and a custom event handler that cancels any download requests. This will prevent the download dialog box from appearing and allow the page content to be downloaded or saved as PDF without any user intervention.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-19 22:57:11 +0000
Seen: 11 times
Last updated: Jun 19 '23
How to obtain a Null value in combo boxes?
What is the process to create an evenly spaced gap using flex box CSS?
Can I utilize a digital dialogue box for selecting both date and time?
How does the accuracy of Scipy FFT compare to that of the analytical FT of a box function?
In Jetpack Compose Dialog, what is the process for drawing behind the system status bar?
How can I make the modal dialog show up after the first click of the actionButton?