[Solved] delphi CEF4 Chromium do not show web sites with secure connection error


By default, CEF cancels the request when a certificate issue occurs during its navigation. Hard to say what you want to do in your case, but in general, you should not work with content with some certificate issue. But if you know that it’s safe for you, you can allow your request(s) to continue at least in these two ways:

1. Handle certificate issues for each request

You can write handler for the OnCertificateError event and handle each request certificate issue separately. With CEF4Delphi library you can do it e.g. this way:

type
  TFormMain = class(TForm)
    ChromiumWindow1: TChromiumWindow;
    procedure FormShow(Sender: TObject);
  private
    procedure ChromiumCertificateError(Sender: TObject; const browser: ICefBrowser;
      certError: TCefErrorcode; const requestUrl: ustring; const sslInfo: ICefSslInfo;
      const callback: ICefRequestCallback; out Result: Boolean);
  end;

procedure TFormMain.FormShow(Sender: TObject);
begin
  ChromiumWindow1.ChromiumBrowser.OnCertificateError := ChromiumCertificateError;
  ChromiumWindow1.CreateBrowser;
end;

procedure TFormMain.ChromiumCertificateError(Sender: TObject; const browser: ICefBrowser;
  certError: TCefErrorcode; const requestUrl: ustring; const sslInfo: ICefSslInfo;
  const callback: ICefRequestCallback; out Result: Boolean);
begin
  Result := False;

  if MessageDlg(Format('Certificate error. Code: %d. Do you want to continue?',
    [Integer(certError)]), mtConfirmation, [mbYes, mbNo], 0) = mrYes then
  begin
    Result := True;
    callback.Cont(True);
  end;
end;

The principle of this event is simple. When you return False to the Result parameter, request that has reported a certificate issue will be immediately cancelled. When you return True to the Result parameter, request navigation will continue. But, except that you must say the request to continue (that’s the call callback.Cont(True) in the above code), either in this event, or in some later one.

If you were interested about specific certificate errors, consult the certError parameter of the event with error code constants prefixed by ERR_CERT_ defined in the uCEFConstants.pas module (for descriptions then see the net_error_list.h header file).

Another way of handling specific certificate errors would be getting status from the sslInfo interface and masking the status value by the CERT_STATUS_ flags (uCEFConstants.pas).

2. Globally ignore all certificate issues

You can enable the ignore_certificate_errors option to globally ignore all certificate issues letting all the created CEF browsers navigate to the content despite all certificate issues (which is unsafe). For CEF4Delphi library you can setup global settings typically in your project source, e.g. like this:

GlobalCEFApp := TCefApplication.Create;
try
  GlobalCEFApp.IgnoreCertificateErrors := True;

  if GlobalCEFApp.StartMainProcess then
  begin
    Application.Initialize;
    Application.MainFormOnTaskbar := True;
    Application.CreateForm(TFormMain, FormMain);
    Application.Run;
  end;
finally
  GlobalCEFApp.Free;
end;

I would discourage from using this way as it may not be safe to navigate to content with certificate issue.

solved delphi CEF4 Chromium do not show web sites with secure connection error