From 4c507bbd17de94858953ec7c619539a7fe044179 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Mon, 26 Aug 2024 14:18:28 +0300 Subject: [PATCH] filters must be reloaded after setting, or there's a chance they won't be ready before Selenium navigates --- sedd/ubo/ubo.py | 5 ++++- sedd/ubo/utils.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/sedd/ubo/ubo.py b/sedd/ubo/ubo.py index 69d3aa0..a889b3f 100644 --- a/sedd/ubo/ubo.py +++ b/sedd/ubo/ubo.py @@ -5,7 +5,8 @@ from ..config import SEDDConfig from .utils import ubo_set_user_settings, \ ubo_set_advanced_settings, ubo_set_selected_filters, \ - ubo_set_whitelist, ubo_set_dynamic_rules, ubo_set_user_filters + ubo_set_whitelist, ubo_set_dynamic_rules, ubo_set_user_filters, \ + ubo_reload_all_filters def init_ubo_settings(browser: Firefox, config: SEDDConfig, ubo_id: str) -> bool: @@ -26,6 +27,8 @@ def init_ubo_settings(browser: Firefox, config: SEDDConfig, ubo_id: str) -> bool ubo_set_whitelist(browser, settings) ubo_set_dynamic_rules(browser, settings) ubo_set_user_filters(browser, settings) + + ubo_reload_all_filters(browser) except: print('Failed to set uBLock config, using defaults') print(exc_info()) diff --git a/sedd/ubo/utils.py b/sedd/ubo/utils.py index 296cd4b..7bcf73f 100644 --- a/sedd/ubo/utils.py +++ b/sedd/ubo/utils.py @@ -82,3 +82,13 @@ def ubo_set_user_filters(browser: Firefox, settings: SEDDUboSettings) -> None: content: toOverwrite.join('\\n') }) """, settings['userFilters']) + + +def ubo_reload_all_filters(browser: Firefox) -> None: + browser.execute_async_script(""" + const done = arguments[0] + + globalThis.vAPI.messaging.send('dashboard', { + what: 'reloadAllFilters', + }).then(done) + """)