Detect page load completion

683 views
Skip to first unread message

marc ruiter

unread,
Dec 4, 2013, 8:15:26 AM12/4/13
to cefp...@googlegroups.com
I'm trying to figure out a way to reliably detect when a page has been entirely loaded including any sub frames. Looking at the examples I thought that the OnLoadEnd callback with frame == browser.GetManFrame() would do the trick but I just saw this comment in client_handler.cpp: "Sub-frames may start or continue loading after the main frame load has ended."

http://code.google.com/p/cefpython/source/browse/cefpython/cef3/client_handler/client_handler.cpp#sl_svn0767285eb64c9faeab7393d0ac8411feb90728fa_544

Is there a more reliable method to detect when all sub frames have been loaded?

Thanks,
Marc

Czarek Tomczak

unread,
Dec 4, 2013, 9:07:00 AM12/4/13
to cefp...@googlegroups.com
Hi Marc,

OnLoadEnd is an equivalent of window.onload in javascript, it waits for all the images to load, sometimes if an image loading hangs up it may take forever. The other solution would be to use DOMContentLoaded, see Issue 32.

A subframe may finish loading before a main frame. I think that you need to keep counting the calls to OnLoadStart() and OnLoadEnd() for all the frames, if they are equal it means that all subframes has finished loading. In a call to OnLoadStart() and when frame->IsMainFrame() is true, you should treat this as a new request and reset the frames counting procedure.

Regardint the comment:
Sub-frames may start or continue loading after the main frame load has ended

You should use Browser.GetFrames()/GetFrameCount() when OnLoadEnd() is called for the main frame. Counting of the frames in OnLoadStart() and OnLoadEnd() may not be enough, so make sure that all subframes started loading by calling Browser.GetFrames() in OnLoadEnd() for the main frame.

Best regards,
Czarek

marc ruiter

unread,
Dec 4, 2013, 10:03:18 AM12/4/13
to cefp...@googlegroups.com
Hi Czarek,

Thanks for the fast response. I guess that I will have to implement my own MessageLoop() so that I can continuously monitor GetFrameCount().

Thanks,
Marc

Czarek Tomczak

unread,
Dec 4, 2013, 10:07:45 AM12/4/13
to cefp...@googlegroups.com
On Wednesday, December 4, 2013 4:03:18 PM UTC+1, marc ruiter wrote:
Thanks for the fast response. I guess that I will have to implement my own MessageLoop() so that I can continuously monitor GetFrameCount().

It is enough to monitor the frames in OnLoadStart() and OnLoadEnd(), I don't think there is a need for a message loop.

-Czarek

marc ruiter

unread,
Dec 4, 2013, 10:27:23 AM12/4/13
to cefp...@googlegroups.com
If the comment I linked to is correct, it might be possible that a sub-frame isn't even started when the main frame has been completed. Therefore, listeing to OnLoadEnd() for the main frame wouldn't necessarily give me all the sub-frames.

Czarek Tomczak

unread,
Dec 4, 2013, 10:33:57 AM12/4/13
to cefp...@googlegroups.com
On Wednesday, December 4, 2013 4:27:23 PM UTC+1, marc ruiter wrote:
If the comment I linked to is correct, it might be possible that a sub-frame isn't even started when the main frame has been completed. Therefore, listeing to OnLoadEnd() for the main frame wouldn't necessarily give me all the sub-frames.

You should call GetFrameCount() in OnLoadEnd() for the main frame so that you know for how many OnLoadEnd() calls you have to wait for the page loading to be recognized as completed.

-Czarek 

marc ruiter

unread,
Dec 4, 2013, 10:38:54 AM12/4/13
to cefp...@googlegroups.com
So GetFrameCount() returns the correct value even if the subframes aren't loaded yet?

Czarek Tomczak

unread,
Dec 4, 2013, 10:47:06 AM12/4/13
to cefp...@googlegroups.com
On Wednesday, December 4, 2013 4:38:54 PM UTC+1, marc ruiter wrote:
So GetFrameCount() returns the correct value even if the subframes aren't loaded yet?

Yes I think that it should. OnLoadEnd() is called for the main frame when whole page is ready to display, so the DOM is ready, so it should know all the frames that are in its content.

You may also try asking this question on the CEF C++ Forum.

-Czarek 

marc ruiter

unread,
Dec 4, 2013, 11:21:49 AM12/4/13
to cefp...@googlegroups.com
If that is indeed the case it makes my life a bit easier :). Anyway thanks for the help.

Czarek Tomczak

unread,
Dec 23, 2013, 1:06:34 PM12/23/13
to cefp...@googlegroups.com
OnLoadingStateChange() may also be used for detecting page load completion.

-Czarek

marc ruiter

unread,
Dec 23, 2013, 6:53:49 PM12/23/13
to cefp...@googlegroups.com
Thanks for the tip. Are the semantics similar to that of OnLoadEnd (all external content loaded etc.) or to DOMContentLoaded?

Thanks,
Marc

Czarek Tomczak

unread,
Dec 24, 2013, 2:26:46 AM12/24/13
to cefp...@googlegroups.com
OnLoadingStateChange is similar to OnLoadEnd, but the signal timing is somewhat different.

-Czarek
Reply all
Reply to author
Forward
0 new messages