Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

Detect when the page finishes loading

Post Reply
thefunkyjoint
Posts: 459
Joined: Thu Aug 10, 2017 12:40 pm

Detect when the page finishes loading

Post 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
User avatar
salvadordf
Posts: 4037
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Detect when the page finishes loading

Post 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
thefunkyjoint
Posts: 459
Joined: Thu Aug 10, 2017 12:40 pm

Re: Detect when the page finishes loading

Post 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.
bullsito
Posts: 32
Joined: Sun Dec 13, 2020 4:19 pm

Re: Detect when the page finishes loading

Post 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.
Post Reply