From 8064e3ea6f4e172775f6c73d83568d5c19084ec5 Mon Sep 17 00:00:00 2001 From: toofar Date: Sun, 13 Oct 2024 20:55:28 +1300 Subject: [PATCH] Disable QtWebEngine's permissions persistence feature QtWebEngine has a new feature where it will remember what permissions you have granted or denied. It has three options regarding permissions storage: AskEveryTime -- don't store StoreInMemory -- store in memory only StoreOnDisk -- store in memory and on disk By default it does the StoreOnDisk behavior. Having webengine remember whether you granted or denied a permission would make the qutebrowser UX around that area inconsistent. For example the default y/n actions for a permission prompt in qutebrowser will only accept that single permission request, and you'll be re-prompted if you reload the page. Users may be used to this and if webengine started remembering permission grants the users may be surprised to find that the page was accessing features without prompting them for permission anymore. Additionally we already have our own permission storage machinery in autoconfig.yml. This commit will set the webengine feature to AskEveryTime, which disables any storing of permission grants. Also adjusts the skip marker of the affected tests so they'll be enabled again on Qt versions with the appropriate permissions API. --- pytest.ini | 2 +- qutebrowser/browser/webengine/webenginesettings.py | 11 ++++++++++- tests/end2end/conftest.py | 4 ++-- tests/end2end/features/prompts.feature | 6 +++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pytest.ini b/pytest.ini index adff9ae7f..9dc54548f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -41,7 +41,7 @@ markers = qt6_only: Tests which should only run with Qt 6 qt5_xfail: Tests which fail with Qt 5 qt6_xfail: Tests which fail with Qt 6 - qt68_beta4_skip: Fails on Qt 6.8 beta 4 + qt68_no_permission_api: Fails on Qt 6.8 with PyQt<6.8 qt_log_level_fail = WARNING qt_log_ignore = # GitHub Actions diff --git a/qutebrowser/browser/webengine/webenginesettings.py b/qutebrowser/browser/webengine/webenginesettings.py index b4f6f8a1b..63f740a2e 100644 --- a/qutebrowser/browser/webengine/webenginesettings.py +++ b/qutebrowser/browser/webengine/webenginesettings.py @@ -26,7 +26,7 @@ from qutebrowser.config import config, websettings from qutebrowser.config.websettings import AttributeInfo as Attr from qutebrowser.misc import pakjoy from qutebrowser.utils import (standarddir, qtutils, message, log, - urlmatch, usertypes, objreg, version) + urlmatch, usertypes, objreg, version, utils) if TYPE_CHECKING: from qutebrowser.browser.webengine import interceptor @@ -281,6 +281,7 @@ class ProfileSetter: self._set_hardcoded_settings() self.set_persistent_cookie_policy() self.set_dictionary_language() + self.disable_persistent_permissions_policy() def _set_hardcoded_settings(self): """Set up settings with a fixed value.""" @@ -345,6 +346,14 @@ class ProfileSetter: self._profile.setSpellCheckLanguages(filenames) self._profile.setSpellCheckEnabled(bool(filenames)) + def disable_persistent_permissions_policy(self): + """Disable webengine's permission persistence.""" + pyqt_version = utils.VersionNumber.parse(version.PYQT_WEBENGINE_VERSION_STR) + if pyqt_version >= utils.VersionNumber(6, 8): + self._profile.setPersistentPermissionsPolicy( + QWebEngineProfile.PersistentPermissionsPolicy.AskEveryTime + ) + def _update_settings(option): """Update global settings when qwebsettings changed.""" diff --git a/tests/end2end/conftest.py b/tests/end2end/conftest.py index 17703d1e1..83c66380d 100644 --- a/tests/end2end/conftest.py +++ b/tests/end2end/conftest.py @@ -192,8 +192,8 @@ def pytest_collection_modifyitems(config, items): 'Skipped on Windows', pytest.mark.skipif, utils.is_windows), - ('qt68_beta4_skip', # WORKAROUND: https://github.com/qutebrowser/qutebrowser/issues/8242#issuecomment-2184542226 - "Fails on Qt 6.8 beta 4", + ('qt68_no_permission_api', # WORKAROUND: https://github.com/qutebrowser/qutebrowser/issues/8242#issuecomment-2184542226 + "Fails on Qt 6.8 with PyQt<6.8", pytest.mark.xfail, machinery.IS_QT6 and version.qtwebengine_versions( avoid_init=True diff --git a/tests/end2end/features/prompts.feature b/tests/end2end/features/prompts.feature index 9e2062d13..2b65bcc56 100644 --- a/tests/end2end/features/prompts.feature +++ b/tests/end2end/features/prompts.feature @@ -251,7 +251,7 @@ Feature: Prompts And I run :click-element id button Then the javascript message "geolocation permission denied" should be logged - @qt68_beta4_skip + @qt68_no_permission_api Scenario: geolocation with ask -> false When I set content.geolocation to ask And I open data/prompt/geolocation.html in a new tab @@ -260,7 +260,7 @@ Feature: Prompts And I run :prompt-accept no Then the javascript message "geolocation permission denied" should be logged - @qt68_beta4_skip + @qt68_no_permission_api Scenario: geolocation with ask -> false and save When I set content.geolocation to ask And I open data/prompt/geolocation.html in a new tab @@ -270,7 +270,7 @@ Feature: Prompts Then the javascript message "geolocation permission denied" should be logged And the per-domain option content.geolocation should be set to false for http://localhost:(port) - @qt68_beta4_skip + @qt68_no_permission_api Scenario: geolocation with ask -> abort When I set content.geolocation to ask And I open data/prompt/geolocation.html in a new tab