delphichromium-embeddeddelphi-10-seattlecef4delphi

How load a local html file with Chromium Embedded (CEF)?


I want load a html file into Chromium (CEF4Delphi) but nothing is showed, only a white page.

Is possible load a local html file using the following approach?

Here is html file.

Also have other trouble that is everytime that Chromium is executed, also is executed other instance of my application. How solve this?

Code used:

var
  Form1: TForm1;
  FStarted: Boolean;

implementation

{$R *.dfm}

function CEFApplication: TCefApplication;
var
  sPath: String;
begin
  sPath := ExtractFilePath(ParamStr(0));
  if not assigned(GlobalCEFApp) then
  begin
    GlobalCEFApp := TCefApplication.Create;
    GlobalCEFApp.FlashEnabled := False;
    GlobalCEFApp.FastUnload := True;

    GlobalCEFApp.FrameworkDirPath := sPath + 'cef';
    GlobalCEFApp.ResourcesDirPath := sPath + 'cef';
    GlobalCEFApp.LocalesDirPath := sPath + 'cef\locales';
    GlobalCEFApp.Cache := sPath + 'cef\cache';
    GlobalCEFApp.Cookies := sPath + 'cef\cookies';
    GlobalCEFApp.UserDataPath := sPath + 'cef\User Data';
    GlobalCEFApp.EnableGPU := False;
  end;
  if not FStarted then
    FStarted := GlobalCEFApp.StartMainProcess;

  result := GlobalCEFApp;
end;

initialization

CEFApplication;

end.

Form2:

procedure TForm2.FormShow(Sender: TObject);
begin
  while not(Chromium1.CreateBrowser(CEFWindowParent1, '')) and
    (Chromium1.Initialized) do
  begin
    Sleep(100);
    Application.processMessages;
  end;
  Chromium1.LoadURL(ExtractFilePath(ExtractFilePath(Application.ExeName)) + 'gmaps.html');
end;

EDITION:

Relative to my doubt about multiple instance of my application being executed, this is normal and right based on this article.


Solution

  • This is how I do it in my code:

    CBrowser.Load('file:///' + ReplaceStr(fpath, '\', '/'));