Question

How to check when WebBrowser has fully completed? This code doesn't work for heavy AJAX websites. It will fire before the site has really completed and thus return HTML code while javascript is still running.

I need to check when the website is FULLY completed. This code was tested with http://www.html5test.com

procedure Browser_DocumentComplete(ASender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
var
  CurWebrowser: IWebBrowser;
  TopWebBrowser: IWebBrowser;
  Document: OleVariant;
  WindowName: string;
begin
  CurWebrowser := pDisp as IWebBrowser;
  TopWebBrowser := (ASender as TEmbeddedWB).DefaultInterface;
  if (CurWebrowser = TopWebBrowser) and not Browser.Busy and (Browser.ReadyState >= READYSTATE_COMPLETE) then begin
    FDocumentLoaded:=True;
    end;
end;
Was it helpful?

Solution

A web page which uses Ajax is loaded by the browser and executes JavaScript to update / modify its content.

The client does not know when a "fully completed" state has been reached. Some JavaScript methods might run after a delay, or periodically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top