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

[REG 5.13] View and page visibility state can be out of sync

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.13.2, 5.14.0 Beta 1
    • 5.13.0
    • WebEngine
    • None
    • 1c33a4a6ae07106513a8105ebbc2d0c65363b333 (qt/qtwebengine/5.13)

    Description

      If you do this:

      QWebEngineView view;
      view.show();
      view.setHtml(QString("<script>window.setTimeout(console.log(document.visibilityState), 100)</script>"), QUrl("about:blank?1"));
      view.hide();
      

      Then the javascript running in the view thinks it is visible. The setHtml() can be any method of triggering a page load, like deserializing an active history item. On 5.12 it correctly reported as hidden. Note that the page visibility being in sync with the widget actually changed with the 5.12 release too (for the better), previously (at least on 5.11) the page reported as visible by default, hence why we are doing the "show then hide" to get them in sync.
      If you remove the show or move the setHtml it works fine, it is just this setup that seems to have the wrong behaviour.

      I have got a bigger reproducer that shows a more real-life setup based on how were loading session in qutebrowser:

      #include <QWebEngineView>
      #include <QApplication>
      #include <QTabWidget>
      #include <QUrl>
      
      QString html(""
      "<html>\n"
      "  <body>\n"
      "    <div id=\"log\" style=\"width: 100%; height: 100%;\"/>\n"
      "  <script>\n"
      "    function report (details) {\n"
      "      let msg = `${window.location.href}: ${details} (${document.visibilityState} and hidden=${document.hidden})`\n"
      "      console.log(msg)\n"
      "      let log = document.getElementById('log')\n"
      "      let d = new Date()\n"
      "      log.innerHTML += `${d.toISOString()} ${msg} <br/>`\n"
      "    }\n"
      "    report('visibility on load')\n"
      "    document.addEventListener('visibilitychange', (...args) => {\n"
      "      report('visibility change')\n"
      "    })\n"
      "  </script>\n"
      "  </body>\n"
      "</html>\n"
      "");
      
      int main(int argc, char **argv) {
          QApplication app(argc, argv);
          int width = 400, height = 600;
      
          // Tab factory that makes tabs visible by default
          QWebEngineView view;
          view.resize(width, height);
          view.show();
      
          QWebEngineView view2;
          view2.resize(width, height);
          view2.show();
      
          // Application logic puts tabs in the state they should be in
          view.setHtml(html, QUrl("about:blank?1"));
          view2.setHtml(html, QUrl("about:blank?2"));
          view2.hide();
      
          QTabWidget tabs;
          tabs.resize(width, height);
          tabs.show();
      
          tabs.insertTab(0, &view, QString("0"));
          tabs.insertTab(1, &view2, QString("1"));
          tabs.setCurrentIndex(0);
          return app.exec();
      }
      

      The tab widget stuff there isn't necessary to reproduce.

      Attachments

        Issue Links

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

          Activity

            People

              juri.valdmann Jüri Valdmann (Inactive)
              toofar toofar
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes