0

I've seen examples in C# where people disabled security (so the user doesn't have to click continue on cert errors) in WebView2 by changing the CoreWebView2EnvironmentOptions, but I can't for the life of me figure out how to do the equivalent with the TEdgeBrowser component in Delphi. Has anyone managed to achieve this in Delphi?

Edit: Updated with a C# solution.

 async void InitializeAsync()
        {
            var op = new CoreWebView2EnvironmentOptions("--disable-web-security");
            var env = await CoreWebView2Environment.CreateAsync(null, null, op);
            await webView.EnsureCoreWebView2Async(env);
        }

Another work around in C#:

var result = await webView.CoreWebView2.CallDevToolsProtocolMethodAsync("Security.setIgnoreCertificateErrors", "{\"ignore\": true}"); 
Doug
  • 1
  • 1
  • Show C# code you've found that does what you need. – fpiette Dec 03 '21 at 15:53
  • The new WebView4Delphi project allows you to disable the security by setting GlobalWebView2Loader.DisableWebSecurity to true. You can also try other properties like GlobalWebView2Loader.AllowInsecureLocalhost. https://github.com/salvadordf/WebView4Delphi – Salvador Díaz Fau Dec 03 '21 at 22:25
  • @Salvador, I have been using your CEF4Delphi since the beginning and I recently swapped it out for TEdgeBrowser in order to use webview2. I can't wait to see your WebView4Delphi and what you have for WebView2, as your CEF4Delphi is 1st class. Before even seeing WebView4Delphi, I'll recommend it, because I know you will keep up with the WebView2 SDK. Yeah! – Greg Dawson Dec 03 '21 at 22:47
  • I have updated the question to have some C# code. I will look at the WebView4Delphi to see if I can figure out how it's done there. Unfortunately I can't use that code directly though, because of auditing reasons. It looks like a great project though. – Doug Dec 04 '21 at 16:11

2 Answers2

1

There are some problems with TEdgeBrowser distributed with Delphi and these problems exist even in Delphi Alexandria. The most obvious of these is that it was conceived at the very beginning of WebView2 in 2020.

The WebView2 unit that ships with Delphi lags far behind in terms of features than a unit generated today from the latest version of WebView2.tlb. Also, I found that the GUID for the ICoreWebView2EnvironmentOptions interface that exists in the WebView2 unit that ships with Delphi is WRONG. When comparing this GUID with the GUID of a WebView2 unit generated from the latest type library, I noticed that they are different and I believe this is not normal.

To solve your problem you need to copy the Vcl.Edge.pas file to your project and modify the TCustomEdgeBrowser.InitializeWebView method. Inside it create an instance of a class that implements the ICoreWebView2EnvironmentOptions interface. You can copy the existing solution in "WebView4Delphi" (The example is in TWVLoader.CreateEnvironment). You will also need to use the uWVTypeLibrary unit which contains the correct GUIDs in place of the original one that comes with Delphi (Winapi.WebView2.pas) and which already contains a set of fixes made by Salvador Días Fau.

Well, this is it. For me this solution worked. I expose a property on the component that allows me to pass additional startup arguments to Edge and there I simply pass "--ignore-certificate-errors" and Edge ignores the certificate errors!

If anyone here wonders why I went to all this trouble instead of using WebView4Delphi, the answer is simple: TEdgeBrowser FOR ME, is much easier to use, as it has only one component and one method to be executed so that everything works as it should. If in the future I need something else from the interfaces I'll consult WebView4Delphi and try to implement in my TEdgeBrowser Frankenstein ;)

0

Unfortunatelly, Delphi 11.1 still does not offer a nice way to control the CoreWebView2EnvironmentOptions.

Instead, you could do this using WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS environement variable:

SetEnvironmentVariable('WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS',
  '--ignore-certificate-errors');
EdgeBrowser.CreateWebView;

Note, --disable-web-security will not remove certificate warnings, but --ignore-certificate-errors will do the trick.

Marcodor
  • 4,578
  • 1
  • 20
  • 24