From f936dfa6486a19899d414d725e94c21a14a5cbfb Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 14 Sep 2024 09:31:22 -0400 Subject: [PATCH] Fix potential failure to unregister scriptlet In Firefox-specific contentScripts API used to register scriptlets. This could potentially occurs when there are registrations pending during a reload of filter lists. --- src/js/scriptlet-filtering.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/js/scriptlet-filtering.js b/src/js/scriptlet-filtering.js index 98f2a64a3..e221a4197 100644 --- a/src/js/scriptlet-filtering.js +++ b/src/js/scriptlet-filtering.js @@ -61,6 +61,7 @@ const contentScriptRegisterer = new (class { runAt: 'document_start', }).then(handle => { this.hostnameToDetails.set(hostname, { handle, code }); + return handle; }).catch(( ) => { this.hostnameToDetails.delete(hostname); }); @@ -94,7 +95,9 @@ const contentScriptRegisterer = new (class { } unregisterHandle(handle) { if ( handle instanceof Promise ) { - handle.then(handle => { handle.unregister(); }); + handle.then(handle => { + if ( handle ) { handle.unregister(); } + }); } else { handle.unregister(); }