[Qtwebengine] How to tell when DOM resources finishes downloading?

Koehne Kai Kai.Koehne at theqtcompany.com
Thu Dec 17 14:24:57 CET 2015

> -----Original Message-----
> From: Kevin Truong [mailto:knt261 at gmail.com]
> Sent: Tuesday, December 15, 2015 10:07 PM
> To: Koehne Kai <Kai.Koehne at theqtcompany.com>
> Cc: qtwebengine at qt-project.org
> Subject: Re: [Qtwebengine] How to tell when DOM resources finishes
> downloading?
> Thanks Kai -- I'll take a look at the submission process later this week.
> Yeah I agree with you it isn't the perfect solution. After the render
> downloads the ajax or iframe, I make it wait 100ms and hope it loads into
> the DOM. This gets most pages correct, but isn't perfect and many still
> serialize too early. Do you have a better idea/suggestion? I know you
> suggested this before:
> > If you know the HTML/AJAX of the specific page, you might be able to
> hook up
> a JS handler that is called when the AJAX request is done, and then signal
> this to the
> C++ world , e.g. via QWebChannel.
> If I understand it correctly, this means I have to know beforehand which
> node gets inserted into the HTML via the ajax/iframe right? E.g. <div
> id="ajax">, and in the javascript, I repeatedly test if div[id=ajax] exists in the
> HTML? 

You indeed have to have knowledge about the page to really decide when it 
is 'finished', because that's a semantic property. Some page might e.g. send
AJAX requests forever (think about a twitter timeline that updates itself regularly).

Anyhow, an alternative would be to just wait until the DOM isn't updated anymore
for some time, but from within the page. You should be able to implement this with  
the help of DOM  Mutation Observers , e.g. something like this

observer.observe(document.documentElement, {
    childList: true,
    subtree: true            

and a timer. 

> I prefer not to use this approach, since my test suite have over 1K
> URLs and I prefer not to write 1K rules by hand for each URL. I'm looking for
> a general way to tell (or approximately tell) when the ajax/iframe/specific
> plug in loads into the DOM, and the signal I patched is currently the only
> thing I could think of.

Fair enough.



More information about the QtWebEngine mailing list