Search code examples
delphimicrosoft-edgewebview2

Allow insecure networks for Delphi Edge Browser component


I am using Edge browser component of Delphi 11.1 in order to automate a navigation process. The problem is that at the start of the navigation process I get the Message "Your connection isn't private" & the whole process stops until I press the button "Advanced" & the button "Continue to 1xx.xx.xx.xx (unsafe)"!

I have to mention that when I navigate to this intranet site via Windows Edge Browser I do not get that Message since I have uploaded the certificate of this site & I have also added it to the exceptions of Edge browser.

I think that I have to set it somehow the "InsecurePrivateNetworkRequestsAllowed" property to true but I cannot find the way or to upload somehow the certificate to Delphi's Edge browser component.

Any Ideas? Thank you.


Solution

  • Insecure connection warning can be bypassed by clicking on the Proceed link.

    Below there is a code sample:

    procedure TForm1.EdgeBrowserNavigationCompleted(Sender: TCustomEdgeBrowser;
      IsSuccess: Boolean; WebErrorStatus: TOleEnum);
    resourcestring
      scProceed =
        'function run() { ' +
        '  var e = document.getElementById("proceed-link"); ' +
        '  if (e) e.click(); ' +
        '} run();';
    begin
      if not IsSuccess and (WebErrorStatus = COREWEBVIEW2_WEB_ERROR_STATUS_CERTIFICATE_IS_INVALID) then
        EdgeBrowser.ExecuteScript(scProceed);
    end;
    

    Another way is to control the WebView2 behaviour using CoreWebView2EnvironmentOptions.AdditionalBrowserArguments. Some of arguments are documented here.

    Currently, Delphi 11.1 does not allow you to manage them using some component/interface, but such options could be set using WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS environement varialble before WebView initialization:

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      SetEnvironmentVariable('WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS',
        '--ignore-certificate-errors');
      EdgeBrowser.CreateWebView;
    end;
    

    Note, this option could be removed in future because of security concerns and sporadic debates on it.