From 13dcd844a7d510fe5fae7dcd71c5a908e38b3195 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 19 Jan 2024 11:00:07 -0500 Subject: [PATCH] Unregister all scriptlets when disabling uBO on a specific site Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3083 This will not completely eliminate the issue but it should lower the likelihood it will occur -- so at least uBO can still benefit from reliable scriptlet execution in Firefox. --- src/js/scriptlet-filtering.js | 11 ++++++++--- src/js/ublock.js | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/js/scriptlet-filtering.js b/src/js/scriptlet-filtering.js index 10da19f0b..806c870bb 100644 --- a/src/js/scriptlet-filtering.js +++ b/src/js/scriptlet-filtering.js @@ -45,10 +45,13 @@ const contentScriptRegisterer = new (class { constructor() { this.hostnameToDetails = new Map(); if ( browser.contentScripts === undefined ) { return; } - onBroadcast(msg => { + this.bc = onBroadcast(msg => { if ( msg.what !== 'filteringBehaviorChanged' ) { return; } - if ( msg.direction > 0 ) { return; } - if ( msg.hostname ) { return this.flush(msg.hostname); } + const direction = msg.direction || 0; + if ( direction > 0 ) { return; } + if ( direction >= 0 && msg.hostname ) { + return this.flush(msg.hostname); + } this.reset(); }); } @@ -78,6 +81,7 @@ const contentScriptRegisterer = new (class { return false; } unregister(hostname) { + if ( hostname === '' ) { return; } if ( this.hostnameToDetails.size === 0 ) { return; } const details = this.hostnameToDetails.get(hostname); if ( details === undefined ) { return; } @@ -85,6 +89,7 @@ const contentScriptRegisterer = new (class { this.unregisterHandle(details.handle); } flush(hostname) { + if ( hostname === '' ) { return; } if ( hostname === '*' ) { return this.reset(); } for ( const hn of this.hostnameToDetails.keys() ) { if ( hn.endsWith(hostname) === false ) { continue; } diff --git a/src/js/ublock.js b/src/js/ublock.js index e963377c3..cfc63497a 100644 --- a/src/js/ublock.js +++ b/src/js/ublock.js @@ -148,7 +148,7 @@ const matchBucket = function(url, hostname, bucket, start) { } bucket.push(directive); this.saveWhitelist(); - filteringBehaviorChanged({ hostname: targetHostname }); + filteringBehaviorChanged({ hostname: targetHostname, direction: -1 }); return true; }