[webkit-qt] patching QtNetworkAccessManager::createRequest

Olivier Tilloy olivier at tilloy.net
Thu Oct 17 23:11:17 PDT 2013

Luca Ottaviano a écrit :
> On 17/10/2013 17:27, Olivier Tilloy wrote:
>> Hi all,
>> I’m looking into patching QtNetworkAccessManager::createRequest(…) to
>> dynamically set a custom user agent on every outgoing HTTP request
>> (setting the experimental.userAgent property on the QML webview is not
>> enough, I need per-domain overrides).
>> I know that with the multi-process architecture the qnam cannot be
>> easily replaced on the application side, and I’m fine with having to
>> minimally patch QtWebKit to achieve my goal (although of course being
>> able to set a custom qnam at runtime would be ideal!).
>> I’m wondering how feasible it would be to have a signal emitted on the
>> webview from createRequest(…) so that I can easily override the UA
>> header dynamically, something similar to the onNavigationRequested
>> signal, and how I would go about implementing such a hook?
>> Any help/pointers/suggestions of an alternative approach much
>> appreciated!
> Hi Olivier,
> I've also looked at WebKit2 internals and I don't think there's an easy
> way to add what you want...
> Maybe you can just change the userAgent in the slot onNavigationRequest
> depending on the target URL, or if that fails because loading is already
> started, you can define a myUrl as a "proxy" for WebView.url.

Changing the webview’s userAgent in onNavigationRequest is the solution 
I’m currently using, but it doesn’t work well enough, the first outgoing 
request always get the default UA.

The local proxy idea is interesting, but I fear this would imply a 
non-negligible performance penalty which I can’t afford.

Thanks for the suggestions anyway!


More information about the webkit-qt mailing list