[Qtwebengine] Modifying request Headers for QML's WebEngineView

Michael Bruning Michael.Bruning at qt.io
Tue May 24 13:15:53 CEST 2016


Hi Neil,


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.


Best regards,

Michael




________________________________
From: neil at copycopy.cc <neil at copycopy.cc> on behalf of Neil Williams <neil+qt at copycopy.cc>
Sent: Tuesday, May 24, 2016 12:53 PM
To: Michael Bruning
Cc: qtwebengine at qt-project.org
Subject: Re: [Qtwebengine] Modifying request Headers for QML's WebEngineView

Hi Michael,

Thanks for the response.

I am aware of those classes but as far as I know QML's WebEngineView does not provide any way to get the underlying QWebEngine (if there is one at all?) which means we would still be looking at mixing the native QWebEngine with QQuickWidgets which is what we are trying to move away from.

Cheers.

On Tue, May 24, 2016 at 11:30 AM, Michael Bruning <Michael.Bruning at qt.io<mailto:Michael.Bruning at qt.io>> wrote:

Hi Neil,


at the moment, we provide the option to set request headers via the Core APIs QWebEngineUrlRequestInterceptor (http://doc.qt.io/qt-5/qwebengineurlrequestinterceptor.html), which can be used to manipulate the request headers using QWebEngineUrlRequestInfo::setHttpHeader (http://doc.qt.io/qt-5/qwebengineurlrequestinfo.html#setHttpHeader) . While these are C++ APIs, it should be possible to use them with an application that uses QML to display the UI.


I am not sure if that would fit the needs you have.


Best regards,

Michael


________________________________
From: QtWebEngine <qtwebengine-bounces+michael.bruning=qt.io at qt-project.org<mailto:qt.io at qt-project.org>> on behalf of Neil Williams <neil+qt at copycopy.cc>
Sent: Tuesday, May 24, 2016 12:06 PM
To: qtwebengine at qt-project.org<mailto:qtwebengine at qt-project.org>
Subject: [Qtwebengine] Modifying request Headers for QML's WebEngineView

Are there any plans to allow modifying of a request header's, or intercept requests via the QML WebEngineView component?

We have a c++ backend with a qml frontend, occasionally we need to display web content within the App authenticated by the request headers (cookies + others). At the moment we have to use QtWebKit (waiting to see if QWebEngine can be submitted to the mac store in 5.7) and swap it around within a QStackedWidget with a Qml Widget. This obviously forces our hand in terms of how our app is composed and it is not ideal.

I am aware that we won't be able to hook QNAM into QWebEngine ever, but allowing more control of the requests that originate from WebEngineView would do for now.

Thanks.

_______________________________________________
QtWebEngine mailing list
QtWebEngine at qt-project.org<mailto:QtWebEngine at qt-project.org>
http://lists.qt-project.org/mailman/listinfo/qtwebengine


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qtwebengine/attachments/20160524/18c1ae2d/attachment.html>


More information about the QtWebEngine mailing list