Cef1 DOMReady event sometimes happens after OnLoadEnd

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Cef1 DOMReady event sometimes happens after OnLoadEnd

Postby kbiskar » Tue Nov 25, 2014 2:49 pm

I'm having an issue when a client may have several of our Cef1 based browsers open at the same time. Occasionally, the page won't load properly when we execute some Javascript after the OnLoadEnd event is fired. This seems to be because the DOM isn't ready at that time, so some javascript functions aren't defined by the time we call them. A simple reload of the page will fix this, but it can still happen later. I can get a workaround in by using a DOMEventListener and DOMVisitor class to wait until the DOM is loaded before executing javascript, but it seems like it should be unnecessary. Is the assumption that the DOM will always be ready before OnLoadEnd incorrect? Is this a bug in Cef1? This problem does not appear to be an issue for our Cef3 browser, but we're still in the process of moving our consumers to our Cef3 browser.
kbiskar
Techie
 
Posts: 25
Joined: Mon May 12, 2014 1:02 pm

Re: Cef1 DOMReady event sometimes happens after OnLoadEnd

Postby magreenblatt » Tue Nov 25, 2014 3:06 pm

kbiskar wrote:Is the assumption that the DOM will always be ready before OnLoadEnd incorrect?

It is incorrect. You should use the DOM event or (in CEF3) OnLoadingStateChange should also work.
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: Cef1 DOMReady event sometimes happens after OnLoadEnd

Postby kbiskar » Thu Dec 11, 2014 8:10 pm

Hey Marshall, thanks for the info. I've decided to use the OnLoadingStateChanged for our Cef3 product and use the DOM Event for our Cef1 version per your suggestions. However, I'm now curious as to the real "meaning" of OnLoadEnd(). If the loading of a page is not tied to having the content/DOM ready to be used, what does this event actually represent?
kbiskar
Techie
 
Posts: 25
Joined: Mon May 12, 2014 1:02 pm

Re: Cef1 DOMReady event sometimes happens after OnLoadEnd

Postby kbiskar » Thu Jan 08, 2015 12:55 pm

I found an issue with using the DOMVisitor. I currently call "frame->VisitDOM(new CustomDomVisitor)" in LoadHandler::OnLoadStart(). However, there is a race condition between when the DOM is actually ready and when the CustomDOMVisitor::Visit() method gets called by CEF. If this gets called after the DOM is already complete, the event will never fire and I will never be notified that the DOM is ready to use. Is there good way around this?
Perhaps by analyzing the DOM for the "window.readyState == 'complete'" or something?
kbiskar
Techie
 
Posts: 25
Joined: Mon May 12, 2014 1:02 pm

Re: Cef1 DOMReady event sometimes happens after OnLoadEnd

Postby magreenblatt » Thu Jan 08, 2015 1:03 pm

You're correct that the document may not exist when OnLoadStart is called. The best solution is likely https://code.google.com/p/chromiumembed ... il?id=1454 if you need to perform the action as soon as the document is created. Otherwise, perform the action later using OnLoadEnd or OnLoadingStateChanged with an |isLoading| value of false.
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: Cef1 DOMReady event sometimes happens after OnLoadEnd

Postby kbiskar » Thu Jan 08, 2015 1:30 pm

The OnLoadingStateChanged method works well, but is only available for Cef3 (I can't wait for all our consumers to move to our Cef3-based product). I had been using OnLoadEnd() in our previous version but this brought up the original issue where we would try to execute queued javascript once OnLoadEnd was called, but it wouldn't work if the DOM wasn't also ready.

I am a little confused though, I had not been trying to explicitly access the document during OnLoadStart(). Does the document need to be ready before calling "frame->Visit()"? I don't quite see what the suggestion is in the link posted, though I may just be a little dense today.
kbiskar
Techie
 
Posts: 25
Joined: Mon May 12, 2014 1:02 pm

Re: Cef1 DOMReady event sometimes happens after OnLoadEnd

Postby magreenblatt » Thu Jan 08, 2015 1:37 pm

Visit() executes asynchronously. OnLoadStart() is likely called before the document exists. If Visit() executes before the document exists then it won't work.
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: Cef1 DOMReady event sometimes happens after OnLoadEnd

Postby kbiskar » Thu Jan 08, 2015 2:23 pm

Ahh, I see. Though the problem I'm having seems to be the opposite. In this case, the Visit() call executes after the DOM is finished loading, so when it adds the event listener, the DOMReady event will never be hit, and I'll never be notified that it's ready.
kbiskar
Techie
 
Posts: 25
Joined: Mon May 12, 2014 1:02 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 38 guests