Ask Your Question
3

What is the method to conceal the Download dialog box in WebView2 during the process of downloading page content or using the "Save as PDF" feature?

asked 2023-06-19 22:57:11 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-19 23:12:02 +0000

devzero gravatar image

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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2023-06-19 22:57:11 +0000

Seen: 11 times

Last updated: Jun 19 '23