Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QWebView: Browser Not Supported

QWebView: Browser Not Supported

Scheduled Pinned Locked Moved Unsolved Qt WebKit
6 Posts 2 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nathanday89
    wrote on 14 Jun 2019, 20:12 last edited by
    #1

    I want to view a webpage in a plugin I'm developing, but I'm running into an issue with QWebView. When I go to the URL "http://192.168.1.76" I get a error that says "Browser not supported...web interface only supports Google Chrome browser" I contacted support of the product I'm trying to pull an image from, and they said that I probably need to send the correct Request headers.

    I tried using QWebEngineView because I read somewhere that it was Chromium based to see if that would resolve the issue, and it doesn't.

    This is the function I use to get to the webpage

    void PickItPlugin::on_pushButton_17_clicked()
    {
        ui->webView->setUrl(QUrl("http://192.168.1.76"));
    }
    

    I use a webview from my UI made in Qt Creator.

    This is the header I get when I inspect the image's URL in the Chrome Browser.

    GET /2d_stream.jpg HTTP/1.1
    Host: 192.168.1.76
    Connection: keep-alive
    Cache-Control: max-age=0
    Upgrade-Insecure-Requests: 1
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
    Accept-Encoding: gzip, deflate
    Accept-Language: en-US,en;q=0.9
    

    My Question is how do I set the Request header properly so I can access the image using QWebView?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Konstantin Tokarev
      wrote on 14 Jun 2019, 22:39 last edited by
      #2

      You probably just need to override userAgentForUrl method in your subclass of QWebPage, and set object of your class into QWebView

      Note that if site explicitly requires Chromium it might rely on some new features of web platform. Make sure that you are using QtWebKit 5.212

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nathanday89
        wrote on 17 Jun 2019, 14:01 last edited by
        #3

        @Konstantin-Tokarev Thank you for your reply.

        I hate to admit this, but I'm not sure how to subclass QWebpage and override the userAgentForUrl. I'm also not sure what I need to set the userAgentForUrl string to.

        Here's what I have tried:

        "webpage.h"

        #include <QWebView>
        
        class WebPage: public QWebPage
        {
        public:
            WebPage();
            QString userAgentForUrl(const QUrl & url);
        };
        
        

        "webpage.cpp"

        #include "webpage.h"
        
        WebPage::WebPage()
        {
        
        }
        
        QString WebPage::userAgentForUrl(const QUrl &url)
        {
            return "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36";
        }
        

        "plugin.cpp"

        void PickItPlugin::on_pushButton_17_clicked()
        {
            ui->webView->setUrl(QUrl("http://192.168.1.72"));
            WebPage page;
            page.userAgentForUrl(QUrl("http://192.168.1.72"));
            ui->webView->setPage(page);
        }
        

        I know that there is a lot wrong with this, but I'm not sure exactly how I need to go about setting all of this up. Any help would be appreciated.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          Konstantin Tokarev
          wrote on 17 Jun 2019, 14:39 last edited by
          #4

          Your code looks correct. You can check if user-agent is really working using test page like https://whatsmyua.info/

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nathanday89
            wrote on 17 Jun 2019, 17:10 last edited by
            #5

            @Konstantin-Tokarev

            Does this do that same thing as below?

            QNetworkRequest request;
            request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; Linux i686) AppleWebKit/538.1 (KHTML, like Gecko) AUBOPE Safari/538.1");
            ui->webView->load(request);
            

            I'm still getting the Browser not supported error.

            I've even tried this:

                QNetworkRequest request;
                request.setRawHeader("Connection", "keep-alive");
                request.setRawHeader("Cache-Control", "max-age=0");
                request.setRawHeader("Upgrade-Insecure-Requests", "1");
                request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; Linux i686) AppleWebKit/538.1 (KHTML, like Gecko) AUBOPE Safari/538.1");
                request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
                request.setRawHeader("Accept-Encoding", "gzip, deflate");
                request.setRawHeader("Accept-Langauge", "en-US,en;q=0.9");
                request.setUrl(QUrl("http://192.168.1.72"));
                ui->webView->load(request);
            
            1 Reply Last reply
            0
            • K Offline
              K Offline
              Konstantin Tokarev
              wrote on 17 Jun 2019, 17:13 last edited by
              #6

              Maybe it doesn't check request headers, but does JS testing of supported features

              1 Reply Last reply
              0

              1/6

              14 Jun 2019, 20:12

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved