Home > Software engineering >  How to add "ignore-certificate-errors" in webview2 WPF
How to add "ignore-certificate-errors" in webview2 WPF

Time:09-27

I am trying to convert WPF chrome browser component to WebView2 .

Chrome have this settings :

        if (Cef.IsInitialized == false)
        {
            var settings = new CefSettings();
            settings.IgnoreCertificateErrors = true;
            Cef.Initialize(settings);
        }

How to Add this in WebView2.

I see some links about it ,but it say it will be support later microsoft-edge-webview2-ignore-certificate-errors . is this supported ?

CodePudding user response:

It is supported in the current release of WebView2 (version 1.0.1343.22).

The way you do it is:

After the WebView2is initialized, you subscribe to the ServerCertificateErrorDetected event, like this:

webView.CoreWebView2.ServerCertificateErrorDetected  = WebView_ServerCertificateErrorDetected;

then inside that eventhandler, you tell it to ignore the error:

void WebView_ServerCertificateErrorDetected(object sender, CoreWebView2ServerCertificateErrorDetectedEventArgs e)
{
   CoreWebView2Certificate certificate = e.ServerCertificate;
   e.Action = CoreWebView2ServerCertificateErrorAction.AlwaysAllow;
}

There's more advanced options available (like only ignore some certificates), but if you just want to allow all certificates, then this should work.

However the question still remains: Why are the certificates invalid and should they be ignored? You can make even self-signed certificates valid on local systems, so they don't throw errors (look it up).

  • Related