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.