Restrict page lifecycle feature to Qt6.5+

There is some weirdness preventing us from connecting to the
`QWebEnginePage.recommendedStateChanged` on WebEngine 6.4 and below. We
get this message from QT:

    qt.core.qobject.connect: QObject::connect: No such signal WebEnginePage::recommendedStateChanged(QWebEnginePage::LifecycleState)

and this message from PyQt:

    TypeError: connect() failed between recommendedStateChanged(QWebEnginePage::LifecycleState) and _on_recommended_state_changed()

We couldn't get to the root of it, but we shouldn't have a pressing need
to support this on older versions anyway since later Qt versions are
already widespread.
This commit is contained in:
toofar 2025-05-20 22:31:43 +12:00 committed by owl
parent 7105003a7d
commit fec97696ae
No known key found for this signature in database
GPG Key ID: C2308C68A80FC991
4 changed files with 17 additions and 2 deletions

View File

@ -1791,7 +1791,8 @@ class WebEngineTab(browsertab.AbstractTab):
page.printRequested.connect(self._on_print_requested)
page.selectClientCertificate.connect(self._on_select_client_certificate)
page.recommendedStateChanged.connect(self._on_recommended_state_changed)
if version.qtwebengine_versions().webengine >= utils.VersionNumber(6, 5):
page.recommendedStateChanged.connect(self._on_recommended_state_changed)
view.titleChanged.connect(self.title_changed)
view.urlChanged.connect(self._on_url_changed)

View File

@ -362,6 +362,9 @@ qt.chromium.use_recommended_page_lifecycle_state:
Ongoing page activity is taken into account when determining the
recommended lifecycle state, as to not disrupt your browsing.
This feature is only available on QtWebEngine 6.5+. On older versions
this setting is ignored.
See the Qt documentation for more details: https://doc.qt.io/qt-6/qtwebengine-features.html#page-lifecycle-api
# yamllint enable rule:line-length

View File

@ -1990,6 +1990,7 @@ Feature: Tab management
And I run :tab-prev
Then "Entering mode KeyMode.insert (reason: mode_override)" should be logged
@qt>=6.5
Scenario: Lifecycle change on tab switch
When I set qt.chromium.use_recommended_page_lifecycle_state to true
And I open about:blank?1

View File

@ -14,12 +14,14 @@ QWebEngineScriptCollection = QtWebEngineCore.QWebEngineScriptCollection
QWebEngineScript = QtWebEngineCore.QWebEngineScript
from qutebrowser.browser import greasemonkey
from qutebrowser.utils import usertypes
from qutebrowser.utils import usertypes, utils, version
webenginetab = pytest.importorskip(
"qutebrowser.browser.webengine.webenginetab")
pytestmark = pytest.mark.usefixtures('greasemonkey_manager')
versions = version.qtwebengine_versions(avoid_init=True)
class ScriptsHelper:
@ -248,6 +250,14 @@ class TestWebEnginePermissions:
class TestPageLifecycle:
@pytest.fixture(autouse=True)
def check_version(self):
# While the lifecycle feature was introduced in 5.14, PyQt seems to
# have trouble connecting to the signal we require on 6.4 and prior.
# https://github.com/qutebrowser/qutebrowser/pull/8547#issuecomment-2890997662
if versions.webengine < utils.VersionNumber(6, 5):
pytest.skip("Lifecycle feature requires Webengine 6.5+")
@pytest.fixture
def set_state_spy(
self,