Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-76249

[Reg 5.9->5.11]Custom UserAgent ignored if page opened with window.open or _blank

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.12.5, 5.13.1, 5.14.0 Alpha
    • 5.11.2, 5.12.3
    • WebEngine
    • None
    • Linux/X11, Windows
    • 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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              kiburtse Kirill Burtsev
              XPlatforms Dzianis Shman
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes