Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. QWebEnginePage headers issue
Forum Updated to NodeBB v4.3 + New Features

QWebEnginePage headers issue

Scheduled Pinned Locked Moved Solved QtWebEngine
2 Posts 1 Posters 743 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.
  • banditoB Offline
    banditoB Offline
    bandito
    wrote on last edited by bandito
    #1

    Using QWebEnginePage to download web pages. Works very well but some it doesn't work with certain URLs and appears to be a header issue. I can't figure out what headers to send to not get this error.

    Header:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QApplication>
    #include <QWebEnginePage>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    private:
        QWebEnginePage *p;
        Ui::MainWindow *ui;
    protected slots:
        void getHtml(bool s);
        void textChanged();
    
    signals:
    
    
    };
    
    #endif // MAINWINDOW_H
    
    

    Source

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QApplication>
    #include <QWebEnginePage>
    #include <QWebEngineSettings>
    #include <QWebEngineHttpRequest>
    
    QWebEngineHttpRequest httpR;
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow){
        ui->setupUi(this);
        p = new QWebEnginePage(this);
        httpR.setHeader("Location", "absoluteURI");
        httpR.setUrl(QUrl("https://ca.finance.yahoo.com/quote/AIPT/history?period1=1238597365&period2=1554130165&interval=1d&filter=history&frequency=1d"));
        p->settings()->setAttribute(QWebEngineSettings::AutoLoadImages, false);
        p->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
        connect(p, SIGNAL(loadFinished(bool)), this, SLOT(getHtml(bool)));
        p->load(httpR);
    
    }
    
    
    QString html = "";
    void MainWindow::getHtml(bool s){
       p->toHtml(
           [this](QString result) {
               html=result;
               this->textChanged();
               qDebug()<<httpR.headers();
        });
    }
    
    void MainWindow::textChanged(){
        qDebug()<<html.size();
    }
    
    MainWindow::~MainWindow(){
        delete ui;
    }
    
    

    Error message:

    js: Unrecognized Content-Security-Policy directive 'disown-opener'.

    js: Unrecognized Content-Security-Policy directive 'disown-opener'.

    860801
    QVector("Location")
    js: Unrecognized Content-Security-Policy directive 'disown-opener'.

    js: Unrecognized Content-Security-Policy directive 'disown-opener'.

    js: Unrecognized Content-Security-Policy directive 'disown-opener'.

    js: The resource https://pagead2.googlesyndication.com/pagead/js/r20190327/r20190131/show_ads_impl.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it Please make sure it has an appropriate as value and it is preloaded intentionally.

    banditoB 1 Reply Last reply
    0
    • banditoB bandito

      Using QWebEnginePage to download web pages. Works very well but some it doesn't work with certain URLs and appears to be a header issue. I can't figure out what headers to send to not get this error.

      Header:

      #ifndef MAINWINDOW_H
      #define MAINWINDOW_H
      
      #include <QMainWindow>
      #include <QApplication>
      #include <QWebEnginePage>
      
      namespace Ui {
      class MainWindow;
      }
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          explicit MainWindow(QWidget *parent = nullptr);
          ~MainWindow();
      
      private:
          QWebEnginePage *p;
          Ui::MainWindow *ui;
      protected slots:
          void getHtml(bool s);
          void textChanged();
      
      signals:
      
      
      };
      
      #endif // MAINWINDOW_H
      
      

      Source

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include <QApplication>
      #include <QWebEnginePage>
      #include <QWebEngineSettings>
      #include <QWebEngineHttpRequest>
      
      QWebEngineHttpRequest httpR;
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow){
          ui->setupUi(this);
          p = new QWebEnginePage(this);
          httpR.setHeader("Location", "absoluteURI");
          httpR.setUrl(QUrl("https://ca.finance.yahoo.com/quote/AIPT/history?period1=1238597365&period2=1554130165&interval=1d&filter=history&frequency=1d"));
          p->settings()->setAttribute(QWebEngineSettings::AutoLoadImages, false);
          p->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
          connect(p, SIGNAL(loadFinished(bool)), this, SLOT(getHtml(bool)));
          p->load(httpR);
      
      }
      
      
      QString html = "";
      void MainWindow::getHtml(bool s){
         p->toHtml(
             [this](QString result) {
                 html=result;
                 this->textChanged();
                 qDebug()<<httpR.headers();
          });
      }
      
      void MainWindow::textChanged(){
          qDebug()<<html.size();
      }
      
      MainWindow::~MainWindow(){
          delete ui;
      }
      
      

      Error message:

      js: Unrecognized Content-Security-Policy directive 'disown-opener'.

      js: Unrecognized Content-Security-Policy directive 'disown-opener'.

      860801
      QVector("Location")
      js: Unrecognized Content-Security-Policy directive 'disown-opener'.

      js: Unrecognized Content-Security-Policy directive 'disown-opener'.

      js: Unrecognized Content-Security-Policy directive 'disown-opener'.

      js: The resource https://pagead2.googlesyndication.com/pagead/js/r20190327/r20190131/show_ads_impl.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it Please make sure it has an appropriate as value and it is preloaded intentionally.

      banditoB Offline
      banditoB Offline
      bandito
      wrote on last edited by
      #2

      So I finally figured it out. It appears to fix the " Unrecognized Content-Security-Policy directive 'disown-opener" error you would have to incorporate the html tag attribute "rel=noopener" in each link tag. However since I want to download html webpages from other sources it would be a bit hard to change each link.

      Instead after some trial and error I found that this header "Upgrade: websocket" fixed the issue.

      1 Reply Last reply
      0

      • Login

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