Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.13.0
-
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
- resulted in
-
QTBUG-78461 [regression in 5.14] WebEngine fails to recover after suspend
-
- Closed
-
For Gerrit Dashboard: QTBUG-77209 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
268795,13 | Fix QWebEnginePage visibility state | 5.13 | qt/qtwebengine | Status: MERGED | +2 | 0 |