delphichromium-embeddedtchromium

TChromium individual resource download completion event?


Currently I've got TWebBrowser embedded in an application which "logs" activity in an online game, so that statistics about that game can be shown to the user. This works fine currently, but TWebBrowser appears to be a mighty bit slower than TChromium. Hence, I've started converting my project to make use of the Delphi TChromium embedded framework (CEF)-3 from : https://bitbucket.org/chromiumembedded/

From this I took the guiclient which can be found in the demos directory of the download.

So far so good - however, it appears the user is able to press a button to navigate away from their current page before the call to "crmBrowserLoadEnd" can be received. This results in my program missing out on data.

As an alternative I figure it might be possible to check what resources complete their individual download. I can hook the event "crmBrowserBeforeResourceLoad" to see which resources "start" loading,. But there doesn't seem to be any event that can tell me the resource has finished loading.

procedure TFrmDBrowser.crmBrowserBeforeResourceLoad(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; out Result: Boolean);
var
  u: TUrlParts;
  Item: TListItem;
begin
  item := LvDataView.Items.Add();
  item.Caption := request.Url;
end;

So, it comes down to:


Solution

  • Got an answer from the Facebook Delphi group, by: Shariful Alam Khan. "use OnLoadStart event"

    Which, turns out is exactly the best way for the above example.

    Source example:

    procedure DataExtractionCallback(const Html: uString);
    begin
      try
        FrmDBrowser.RunDataExtraction(Html);
      except
        //
      end;
    end;
    
    procedure TFrmDBrowser.crmBrowserLoadStart(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame);
    var
      CefStringVisitor: ICefStringVisitor;
      URL: String;
    begin
      if not IsMain(browser, frame) then
        Exit;
    
      FLoading := True;
    
      CefStringVisitor := TCefFastStringVisitor.Create(DataExtractionCallback);
      crmBrowser.Browser.MainFrame.GetSource(CefStringVisitor);
    end;