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

QWebEngineProfile is broken after click on link with target _blank

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Not Evaluated Not Evaluated
    • 5.10.1
    • 5.10.0
    • WebEngine
    • None
    • Windows 10, MSVC 2015, 64 bit

      I have a JavaScript which should be injected in every website loaded in a WebEngineView.

      Therefore I create a QWebEngineProfile where I add my Script.

      The JS stops working if I do the following steps i.e. in the demo browser example:

      1.  Load any page on which there is a link with target="_blank".
      2. Click on this link, a new tab opens. The injected JS is working in both tabs.
      3. Close the new opened tab. The old tab gets active again. JS still working.
      4. Click inside the old active tab on any other link.
      5. After the new page loaded, the JS is not injected any more (or broken).

      The expected behavior is that the JS is injected and executed inside the new loaded page.

      I was able to reproduce this behavior in the "simple browser" example. With the following changes:

      BrowserWindow *Browser::createWindow(bool offTheRecord)
      {{{}}
          QWebEngineProfile *testProfile = new QWebEngineProfile("TestJavaScriptStore");

          QWebEngineScript script;
          script.setName("test.js");
          script.setSourceCode("alert('test');");
          script.setWorldId(QWebEngineScript::ApplicationWorld);
          script.setInjectionPoint(QWebEngineScript::DocumentCreation);
          script.setRunsOnSubFrames(true);
          testProfile->scripts()->insert(script);

          auto profile = offTheRecord ? &m_otrProfile : testProfile;
          auto mainWindow = new BrowserWindow(this, profile);
          m_windows.append(mainWindow);
          QObject::connect(mainWindow, &QObject::destroyed, [this, mainWindow]() {
              m_windows.removeOne(mainWindow);
          });
          mainWindow->show();
          return mainWindow;
      }

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

            qt_webengine_team Qt WebEngine Team
            schaef Christoph Schaefer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes