Details
Description
I'd expect it to be possible to turn off the JavaScriptEnabled setting and then turn it on selectively in acceptNavigationRequest. This works with QtWebKit, but with QtWebEngine, another refresh is needed until the page loads properly (with the example of Travis CI). Example:
#include <QApplication> #include <QWebEngineView> #include <QWebEnginePage> #include <QWebEngineSettings> #include <QUrl> #include <QTimer> #include <QDebug> class WebPage : public QWebEnginePage { bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame); }; bool WebPage::acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame) { qDebug() << url; if (isMainFrame && url.toString().contains("travis-ci")) { settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true); } return true; } int main(int argc, char *argv[]) { QApplication app(argc, argv); QWebEngineView view{}; WebPage page{}; view.setPage(&page); QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false); view.load(QUrl("https://www.example.com/")); view.show(); QTimer::singleShot(2000, [&](){ view.load(QUrl("https://www.travis-ci.com/")); }); QTimer::singleShot(4000, [&](){ view.reload(); }); return app.exec(); }
Attachments
Issue Links
- resulted in
-
QTBUG-68424 tst_QWebEngineSettings::setInAcceptNavigationRequest is flaky
-
- Closed
-
For Gerrit Dashboard: QTBUG-66656 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
229525,2 | Keep settings synchronized when RVH swaps | 5.11 | qt/qtwebengine | Status: MERGED | +2 | 0 |
230232,2 | Apply settings on pending RVH too | 5.11 | qt/qtwebengine | Status: MERGED | +2 | 0 |