[Qtwebengine] Modifying request Headers for QML's WebEngineView

Neil Williams neil+qt at copycopy.cc
Tue May 24 19:37:38 CEST 2016


Thanks to you both for your help, QQuickWebEngineProfile did seem to do the
trick.

One thing I found a little odd was that the 'Cookie' header (set in the
interceptor) was overwritten by the contents of the Cookies stored in the
QWebEngineCookieStore.

So if the QWebEngineCookieStore retrieved from the QQuickWebEngineProfile
was empty, setting the 'Cookie' header in the interceptor would work,
otherwise the contents of the proper cookie store seemed to overwrite the
header.

Not a massive issue as we will probably go down the route of keeping the
our QNetworkCookieJar in sync with the QWebEngineCookieStore but a little
unexpected.


On Tue, May 24, 2016 at 1:21 PM, Kai Koehne <Kai.Koehne at qt.io> wrote:

>
>
> > -----Original Message-----
> > From: QtWebEngine [mailto:qtwebengine-bounces+kai.koehne=qt.io at qt-
> > project.org] On Behalf Of Michael Bruning
> > [...]
> > if you would like to intercept the request directly in QML, then you're
> right,
> > that's not possible at the moment. You could however create a C++ class
> that
> > derives from QObject and, add a Q_INVOKABLE to it that takes some
> > parameters that you pass to it from the qml side and creates a
> > QWebEngineUrlRequestInterceptor that can be installed on the
> > QQuickWebEngineProfile. Then you could register your class as a QML type
> > and access it from within your QML code. It's not a very simple /
> straight
> > forward solution, but it may work.
>
> We consciously decided _not_ to support filtering inside QML, because this
> would require syncing between the IO thread and the GUI thread (where QML
> runs).
>
> Anyhow, setting it up in C++ is really easy. QQuickWebEngineProfile is a
> public C++ class, so you can just create  an instance e.g. in main.cpp,
> set up the interceptor, and expose the profile object to Qt Quick, where
> you can
> set it as  active profile on your WebEngineView.
>
> http://doc.qt.io/qt-5/qquickwebengineprofile.html
>
>
> Regards
>
> Kai
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qtwebengine/attachments/20160524/c7b5421a/attachment.html>


More information about the QtWebEngine mailing list