From 0ab1e3b757ceaea0bd4d354d61d0bb2c84652ec2 Mon Sep 17 00:00:00 2001 From: toofar Date: Sun, 13 Oct 2024 18:52:29 +1300 Subject: [PATCH] Clear webengine's permissions.json on start To avoid WebEngine remembering granted permissions across restarts, remove their persistence file when we start up. This is only technically required when Qt=>6.8 and PyQt<6.8. But we only take action if the file exists anyway, so it's safe enough to run all the time and that means less conditional code to test ;) There are a few options for where we could do this cleanup, I'm choosing to do it at the latest point possible, which is right before we set `setPersistentStoragePath()`, since the permissions manager is re-initialized after that, see https://bugreports.qt.io/browse/QTBUG-126595 TODO: * call the new setPersistentPermissionsPolicy API when PyQt>=6.8 --- .../browser/webengine/webenginesettings.py | 21 +++++++++++++++++++ tests/end2end/test_invocations.py | 1 - 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/qutebrowser/browser/webengine/webenginesettings.py b/qutebrowser/browser/webengine/webenginesettings.py index a9dd3e5ef..b4f6f8a1b 100644 --- a/qutebrowser/browser/webengine/webenginesettings.py +++ b/qutebrowser/browser/webengine/webenginesettings.py @@ -392,6 +392,26 @@ def _init_profile(profile: QWebEngineProfile) -> None: _global_settings.init_settings() +def _clear_webengine_permissions_json(): + """Remove QtWebEngine's persistent permissions file, if present. + + We have our own permissions feature and don't integrate with their one. + This only needs to be called when you are on Qt6.8 but PyQt<6.8, since if + we have access to the `setPersistentPermissionsPolicy()` we will use that + to disable the Qt feature. + This needs to be called before we call `setPersistentStoragePath()` + because Qt will load the file during that. + """ + permissions_file = pathlib.Path(standarddir.data()) / "webengine" / "permissions.json" + if permissions_file.exists(): + try: + permissions_file.unlink() + except OSError as err: + log.init.warning( + f"Error while cleaning up webengine permissions file: {err}" + ) + + def _init_default_profile(): """Init the default QWebEngineProfile.""" global default_profile @@ -414,6 +434,7 @@ def _init_default_profile(): f" Early version: {non_ua_version}\n" f" Real version: {ua_version}") + _clear_webengine_permissions_json() default_profile.setCachePath( os.path.join(standarddir.cache(), 'webengine')) default_profile.setPersistentStoragePath( diff --git a/tests/end2end/test_invocations.py b/tests/end2end/test_invocations.py index fb992fc63..a5a03ecf6 100644 --- a/tests/end2end/test_invocations.py +++ b/tests/end2end/test_invocations.py @@ -636,7 +636,6 @@ def test_cookies_store(quteproc_new, request, short_tmpdir, store): quteproc_new.wait_for_quit() -@pytest.mark.qt68_beta4_skip def test_permission_prompt_across_restart(quteproc_new, request, short_tmpdir): # Start test process args = _base_args(request.config) + [