Page 1 of 1

Detect when the page finishes loading

Posted: Fri Sep 20, 2019 12:26 am
by thefunkyjoint
Hello,

Let's say you navigate to a page. The page finishes loading, but the user clicks in a button on the page that loads a lof ot ajax requests, but don't change the url.

What is the best way to really know when the page finishes the loading all the ajax request and is ready ?

Thanks

Re: Detect when the page finishes loading

Posted: Fri Sep 20, 2019 9:34 am
by salvadordf
This is a very old post from the CEF project maintainer :
https://magpcss.org/ceforum/viewtopic.php?f=6&t=12738
AJAX requests can be executed at any time and on an ongoing basis. There is no way to know when an arbitrary website has completed all AJAX requests.
However, I would try to use these events :
  • TChromium.OnLoadingStateChange : to track the general loading state.
  • TChromium.OnLoadStart and TChromium.OnLoadEnd : to check that all frames are fully loaded.
  • TChromium.OnBeforeResourceLoad and TChromium.OnResourceLoadComplete : to check that all resources are fully loaded.
If you open the DevTools and you see requests in the network tab that you can't track with all those events then I would consider checking the DevTools protocol to see if it's possible to get all that info remotely.
https://chromedevtools.github.io/devtools-protocol/
https://github.com/aslushnikov/getting- ... /README.md

Re: Detect when the page finishes loading

Posted: Fri Sep 20, 2019 11:35 am
by thefunkyjoint
It's really a tricky problem... What i'm doing so far is to use a TTimer to periodically check if the html source contains an expected element that would indicate the page ends loading. But this leads to a lot of CPU usage and sometimes i'm receiving an 'Out of memory' crash.

Re: Detect when the page finishes loading

Posted: Mon Dec 14, 2020 6:25 pm
by bullsito
well My solution is the follow.

on Title Change set a flag
then o LoadEnd if flag is true then you know that the page finish Loading.
we dont care about ajax request because can be all the time so theoritically page never finish load but id does with this trick.