Unable to traverse each DOM node for some URLs

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.

Unable to traverse each DOM node for some URLs

Postby gigi777 » Wed Mar 14, 2018 7:53 pm

Hi,

I need to traverse the entire DOM for loaded URLs and make read-only access to each DOM node.
I subclassed CefDOMVisitor and made the following call from the OnProcessMessageReceived() method of CefRenderProcessHandler.
This message to the render process is being made from the OnLoadEnd() method of the CefLoadHandler.
browser->GetMainFrame()->VisitDOM(new MyDOMVisitor(browser));

This seems to work well for static URIs and I can traverse the entire DOM.
But for more complicated URLs, the CefDOMDocument only contains the shell nodes.
For example, for www.google.com, the Visit method of my CefDOMVisitor is called with a CefDOMDocument that has are empty BODY and SCRIPT nodes.
Any idea what could be going wrong?

Thanks.
gigi777
Techie
 
Posts: 13
Joined: Fri Aug 11, 2017 5:35 pm

Re: Unable to traverse each DOM node for some URLs

Postby magreenblatt » Wed Mar 14, 2018 9:01 pm

Content that loads asynchronously will not be loaded by the time OnLoadEnd is called.
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: Unable to traverse each DOM node for some URLs

Postby gigi777 » Thu Mar 15, 2018 1:12 pm

Thanks, Marshall, for the reply.
Is there any way to check and wait for loading of async content using the current CEF APIs?
gigi777
Techie
 
Posts: 13
Joined: Fri Aug 11, 2017 5:35 pm

Re: Unable to traverse each DOM node for some URLs

Postby magreenblatt » Thu Mar 15, 2018 4:50 pm

Anything you do will likely require detailed knowledge of the expected website DOM structure. I would suggest using DOM mutation observers registered with JavaScript.
magreenblatt
Site Admin
 
Posts: 12407
Joined: Fri May 29, 2009 6:57 pm

Re: Unable to traverse each DOM node for some URLs

Postby gigi777 » Thu Mar 15, 2018 7:03 pm

I already have it instrumented waiting on JavaScript document.fonts.ready event to indicate that the document is loaded after OnLoadEnd() event.
As this point, I traverse the JavaScript DOM and can manipulate the nodes, as necessary - all the async content has already been loaded at the time.
Next, I switch over to the native code and try to visit the DOM structure using the VisitDOM API. This does not work as expected.
So, although the JavaScript finds that the async content is loaded, CefDOMDocument seems incomplete.
Any idea why?
gigi777
Techie
 
Posts: 13
Joined: Fri Aug 11, 2017 5:35 pm


Return to Support Forum

Who is online

Users browsing this forum: richardmgoodin and 42 guests