2

I've looked for different ways to check when a page is fully loaded by the TChromium component - for now, unsuccessfully.

I tried to use a delay loading the page and send information about completion through an additional variable, but the event OnLoadEnd is triggered before JS and other similar, so do not always get the correct information.

procedure Chromium1.OnLoadEnd(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; httpStatusCode: Integer);
var EndTime: TTime;
begin
  EndTime := IncSecond(Now, 2);

  repeat Application.ProcessMessages until (Now > EndTime);

  IsChromiumBusy := False;
end;

I read that I can do JS injection and add an object that should appear at the end:

Chromium1.Load('https://www.wp.pl');
Form1.Chromium1.Browser.MainFrame.ExecuteJavaScript('$("body").prepend(''<input type="text" id="msoftval" value=""/>'')', '', 0);
Form1.Chromium1.Browser.MainFrame.ExecuteJavaScript('$("#msoftval").val($("body").html());', '', 0);
Form1.Chromium1.Browser.MainFrame.VisitDomProc(getResult);
while result = '' do Application.ProcessMessages;

But i don't understand usage of VisitDomProc(getResult) with procedure inside of it (why procedure is an argument to VisitDomProc?):

procedure getResult(const doc: ICefDomDocument);
var
  q: ICefDomNode;
begin
  q := doc.GetElementById('msoftval');
  if Assigned(q) then
    result := q.GetValue
  else
    result := '';
end;

What should i declare as result and when to get it? Can someone explain it to me?

Thanks for advices.

kwadratens
  • 187
  • 15

1 Answers1

1

I needed some time to understand that modern pages cannot be read "to the end" and even for some elements of the code, you can not consider completing the code loading, because it generates during the page's operation. Therefore, the question was not so unfounded as it did not make sense at all - the complexity of modern techniques does not allow us to state whether the page has been fully loaded.

Most of the portals that can view such a browser have its own API, and the crawler based on "loading" the page to the end does not make much sense. I solved my problems with no-API pages so that I set myself a TTimer component, for example for a second-maybe two. The procedure is as follows - TChromium.Load(link), then wait for the information from the browser that it is free (as described above), reset TTimer, and then when it appears its TTimer.OnTime load the browser code. Possibly adjust the wait time.

The subject is closed and I apologize for such a stupid question.

kwadratens
  • 187
  • 15