From b061db229e39f94cd6748084acfd1f382a1afe16 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 30 Oct 2023 10:44:04 -0400 Subject: [PATCH] Prevent `contentScripts.register` from throwing Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/2915 --- src/js/scriptlet-filtering.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/js/scriptlet-filtering.js b/src/js/scriptlet-filtering.js index 037f399e0..910905346 100644 --- a/src/js/scriptlet-filtering.js +++ b/src/js/scriptlet-filtering.js @@ -78,6 +78,7 @@ const contentScriptRegisterer = new (class { } register(hostname, code) { if ( browser.contentScripts === undefined ) { return false; } + if ( hostname === '' ) { return false; } const details = this.hostnameToDetails.get(hostname); if ( details !== undefined ) { if ( code === details.code ) { @@ -94,6 +95,8 @@ const contentScriptRegisterer = new (class { runAt: 'document_start', }).then(handle => { this.hostnameToDetails.set(hostname, { handle, code }); + }).catch(( ) => { + this.hostnameToDetails.delete(hostname); }); this.hostnameToDetails.set(hostname, { handle: promise, code }); return false;