Reputation: 11
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);
}
var result = await webView.CoreWebView2.CallDevToolsProtocolMethodAsync("Security.setIgnoreCertificateErrors", "{\"ignore\": true}");
Upvotes: 1
Views: 1196
Reputation: 744
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 ;)
Upvotes: 2
Reputation: 5741
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.
Upvotes: 0