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

Koehne Kai Kai.Koehne at theqtcompany.com
Wed Nov 25 09:14:38 CET 2015


> -----Original Message-----
> From: Kevin Truong [mailto:knt261 at gmail.com]
> Sent: Tuesday, November 24, 2015 7:15 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?
> 
> Sure Kai -- here's my use case: I have a page that loads ajax data into the
> document. The ajax gets loaded into the DOM much later than when the
> DomContentLoaded and the Load event is triggered (the red and blue vertical
> lines in the picture under "Network Panel Overview"
> https://developer.chrome.com/devtools/docs/network). If I understood
> correctly, it means the ajax is loaded much later than when loadFinished() is
> signaled as well. The amount of time we have to wait before the ajax is loaded
> into the document is variable -- it can take 50ms, or it can take up to 10 seconds.
> I would like to know exactly when the ajax is loaded into the DOM (or if that's
> not possible, exactly when the render finish downloading the ajax) before
> serializing/downloading the HTML of the page and doing tests on the HTML. This
> is because the HTML changes after the ajax is loaded into the DOM, and the
> tests need to be run on the updated HTML, not the initial HTML.

I see. 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.

> I'd like this to be generalized as well (not just ajax, but any other DOM resource),
> because I have test pages where the exact same thing happens, but with iframes
> instead of ajax, or with certain very specific plug-ins (like the facebook posts
> that load below an article page). These resources load independently of
> DomContentLoaded and the Load event. However, I can identify them either via
> the URL or the content type -- I just need to figure out how I can tell the render
> to serialize only right after these resources are loaded.

I'm afraid that's not possible right now in the general case. In Qt 5.6 we'll add
QWebEngineUrlRequestInterceptor:

http://doc-snapshots.qt.io/qt5-5.6/qwebengineurlrequestinterceptor.html

But that is called _before_ the request hits the networking stack.

But even if you would have a way to get notified when the network request is 
done, it doesn't mean that the page is re-rendered/the DOM being updated.

Regards

Kai



More information about the QtWebEngine mailing list