Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.11.2, 5.12.3
-
None
-
-
3b04c83620a465a4f8876413c37696fbbc3a23d6 (qt/qtwebengine/5.12)
Description
Some Websites use JavaScript property userAgent of JS navigator object to check UserAgent of the browser. With our custom Qt WebEngine webbrowser we have problem what userAgent property of navigator object in JS ist set to default WebEngine value if the webpage opened with javascript window.open or by clicking on link with target "_blank". Even if
qDebug() << this/*(subclass of QWebEnginePage)*/->profile()->httpUserAgent();
and
qDebug() << QWebEngineProfile::defaultProfile()->httpUserAgent();
return correct UserAgent string.
Overriding interceptRequest(QWebEngineUrlRequestInfo &info) function of QWebEngineUrlRequestInterceptor in subclass and setting header on each interception with info.setHttpHeader("User-Agent", USER_AGENT); doesn't helps.
This can be reproduced by using Qt's WebEngineWidget SimpleBrowser from here: SimpleBrowser
and adding for example:
QWebEngineProfile::defaultProfile()->setHttpUserAgent("Custom Default Agent");
in constructor function of Browser class
+ changing WebPage class constructor to
WebPage::WebPage(QWebEngineProfile *profile, QObject *parent) : QWebEnginePage(profile, parent) { this->profile()->setHttpUserAgent("MY AGENT"); ....
Then run and open for example this webpage: http://kiev.tm/user-agent.php
- You'll see correct UserAgent string set to "MY AGENT"
- click on one of the links which begins with "Click me"
- UserAgent in new opened window/tab will be default one for WebEngine, like: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.3 Chrome/69.0.3497.128 Safari/537.36"
if you add
qDebug() << this->profile()>httpUserAgent();
somewhere in WebPage class the output will be correct UserAgent "MY AGENT"
Attachments
Issue Links
- relates to
-
QTBUG-50876 Custom user agent is not carried over when opening a new tab/page via HTML form button
- Closed
-
QTBUG-61174 Clicking on a link that opens with a _blank target will cause it to not pick up a customized user agent string
- Closed