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

Initiator for XHR is null on unregistered schemes

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P3: Somewhat important
    • None
    • 5.11.2, 5.12
    • WebEngine
    • None

    Description

      When using the WebUI example with QTWEBENGINE_REMOTE_DEBUGGING and doing this in the JS console, the application quits like expected:

      let xhr = new XMLHttpRequest();
      xhr.open("POST", 'webui:about', true);
      xhr.send();
      

      However, when commenting out the call to WebUiHandler::registerUrlScheme();, that does not work anymore, as (presumably since https://codereview.qt-project.org/#/c/234849/) the initiator is QUrl("null").

      Not sure if that's to be expected?

      Complete modifications to WebUI with logging:

      diff --git a/examples/webenginewidgets/webui/main.cpp b/examples/webenginewidgets/webui/main.cpp
      index 54e0c145..21a0d3cc 100644
      --- a/examples/webenginewidgets/webui/main.cpp
      +++ b/examples/webenginewidgets/webui/main.cpp
      @@ -58,7 +58,7 @@
       int main(int argc, char *argv[])
       {
           QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
      -    WebUiHandler::registerUrlScheme();
      +    //WebUiHandler::registerUrlScheme();
       
           QApplication app(argc, argv);
       
      diff --git a/examples/webenginewidgets/webui/webuihandler.cpp b/examples/webenginewidgets/webui/webuihandler.cpp
      index 42446b88..96a51ca7 100644
      --- a/examples/webenginewidgets/webui/webuihandler.cpp
      +++ b/examples/webenginewidgets/webui/webuihandler.cpp
      @@ -54,6 +54,7 @@
       #include <QFile>
       #include <QWebEngineUrlRequestJob>
       #include <QWebEngineUrlScheme>
      +#include <QDebug>
       
       WebUiHandler::WebUiHandler(QObject *parent)
           : QWebEngineUrlSchemeHandler(parent)
      @@ -71,6 +72,8 @@ void WebUiHandler::requestStarted(QWebEngineUrlRequestJob *job)
           QUrl url = job->requestUrl();
           QUrl initiator = job->initiator();
       
      +    qDebug() << "originator: " << initiator;
      +
           if (method == GET && url == webuiAboutUrl) {
               QFile *file = new QFile(QStringLiteral(":/about.html"), job);
               file->open(QIODevice::ReadOnly);
      

      Attachments

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

        Activity

          People

            qt_webengine_team Qt WebEngine Team
            the compiler Florian Bruhin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes