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

[REG 5.13] Pages loaded in background may scroll to the wrong position

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3: Somewhat important
    • 5.14.1
    • 5.13.0
    • WebEngine
    • None
    • qtwebengine-chromium: def0535296788e231759e223afe658453f08433b

    Description

      Similar to https://bugreports.qt.io/browse/QTBUG-54172 when a view that has never been visible is asked to load a page with an anchor it may end up being scrolled to the wrong position when shown. Possibly `.resize()` doesn't end up flowing through to the renderer until it is first shown. Or something.

      Here is a reproducer, on 5.12.4 the background tab scrolls to the expected place initially and thus the two window.scrollY numbers reported are the same. On 5.13 they are different and they should be more different if more content is added to the other element.

      Showing the tab (and then hiding it again) before loading makes it work fine.

      <html>
        <body style="height: 1200px">
          <div id="spacer" style="height: 200px"></div>
          <div id="other">
            <p>Other content</p>
          </div>
          <div id="anchor">Scroll to here</div>
        </body>
      </html>
      
      #include <QWebEngineView>
      #include <QApplication>
      #include <QTabWidget>
      #include <QUrl>
      #include <QTimer>
      
      int main(int argc, char **argv)
      {
          QApplication app(argc, argv);
          int width = 400;
          int height = 600;
      
          QTabWidget tabs;
          tabs.resize(width, height);
          tabs.show();
      
          QWebEngineView view;
          view.resize(width, height);
          tabs.insertTab(0, &view, QString("0"));
      
          QWebEngineView view2;
          view2.resize(width, height);
          tabs.insertTab(1, &view2, QString("1"));
      
          view.load(QUrl("file:///tmp/long.html?1#anchor"));
          view2.load(QUrl("file:///tmp/long.html?2#anchor"));
          tabs.setCurrentIndex(0);
      
          QTimer::singleShot(100, [&app, &tabs, &view2]() {
              tabs.setCurrentIndex(1);
              view2.page()->runJavaScript(QString("console.log(window.scrollY)"));
              view2.page()->runJavaScript(QString("document.getElementById('anchor').scrollIntoView()"));
              view2.page()->runJavaScript(QString("console.log(window.scrollY)"));
          });
          return app.exec();
      }
      

      Attachments

        Issue Links

          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
              toofar toofar
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes