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

QWebEnginePage.LifecycleState API leads to blank webpage after a page's lifecycleState changes back to Active

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.15.0 Beta4
    • 5.14.2
    • WebEngine
    • None
    • Linux/X11

    Description

      Hi,

      QT 5.14 introduced the QWebEnginePage.LifecycleState API. While playing
      with this API to try to suspend inactive browser tabs after certain time,
      I noticed an issue.

      1. Two tabs are created to open example.com.
      2. After 2 seconds, one tab's QWebEnginePage is put into QWebEnginePage::LifecycleState::Discarded state
      3. Switch to the discarded will change its QWebEnginePage's LifecycleState to QWebEnginePage::LifecycleState::Active.

      However the page is completely blank. Web
      Inspector shows HTML source was already there and I can even select
      an invisible element somewhere on the page to inspect it. If I switch to the other tab and then switch back, the page will be shown.

      Here's the full code for the above description (or download the attached .zip file),

      1. file.pro

      TEMPLATE = app

      QT += webenginewidgets

      SOURCES += main.cpp

       

      2. main.cpp

      #include <QApplication>
      #include <QWebEngineView>
      #include <QTabWidget>
      #include <QWebEnginePage>
      #include <QTimer>

      QTabWidget *tab_widget_;

      QWebEngineView *views_[2];

      void current_tab(int i)

      { printf("%d state=%d\n", i, (int)views_[i]->page()->lifecycleState()); }

      void discard_tab() {
      QWebEnginePage *page;
      for (int i=0; i<2; i++)

      { page = views_[i]->page(); page->setLifecycleState(QWebEnginePage::LifecycleState::Discarded); printf("%d state=%d\n", i, (int)page->lifecycleState()); }

      }

      int main(int argc, char *argv[])
      {
      QApplication app(argc, argv);

      QUrl qurl = QUrl(QStringLiteral("http://example.com"));

      QTabWidget tab_widget;
      tab_widget_ = &tab_widget;
      QWebEngineView views[2];
      for (int i=0; i<2; i++)

      { views_[i] = &views[i]; views[i].setUrl(qurl); views[i].resize(1024, 750); tab_widget.addTab(&views[i], "tab1"); }

      // discard tab after
      QTimer::singleShot(2000, &discard_tab);
      printf("discard=%d\n", (int)QWebEnginePage::LifecycleState::Discarded);
      QObject::connect(&tab_widget, &QTabWidget::currentChanged, &current_tab);

      tab_widget.show();

      return app.exec();
      }

      Attachments

        1. minimal.zip
          1 kB
          Coiby Xu
        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)
            coiby Coiby Xu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes