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.
This commit is contained in:
Raymond Hill 2024-01-19 11:00:07 -05:00
parent 5e9a7c60db
commit 13dcd844a7
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 9 additions and 4 deletions

View File

@ -45,10 +45,13 @@ const contentScriptRegisterer = new (class {
constructor() { constructor() {
this.hostnameToDetails = new Map(); this.hostnameToDetails = new Map();
if ( browser.contentScripts === undefined ) { return; } if ( browser.contentScripts === undefined ) { return; }
onBroadcast(msg => { this.bc = onBroadcast(msg => {
if ( msg.what !== 'filteringBehaviorChanged' ) { return; } if ( msg.what !== 'filteringBehaviorChanged' ) { return; }
if ( msg.direction > 0 ) { return; } const direction = msg.direction || 0;
if ( msg.hostname ) { return this.flush(msg.hostname); } if ( direction > 0 ) { return; }
if ( direction >= 0 && msg.hostname ) {
return this.flush(msg.hostname);
}
this.reset(); this.reset();
}); });
} }
@ -78,6 +81,7 @@ const contentScriptRegisterer = new (class {
return false; return false;
} }
unregister(hostname) { unregister(hostname) {
if ( hostname === '' ) { return; }
if ( this.hostnameToDetails.size === 0 ) { return; } if ( this.hostnameToDetails.size === 0 ) { return; }
const details = this.hostnameToDetails.get(hostname); const details = this.hostnameToDetails.get(hostname);
if ( details === undefined ) { return; } if ( details === undefined ) { return; }
@ -85,6 +89,7 @@ const contentScriptRegisterer = new (class {
this.unregisterHandle(details.handle); this.unregisterHandle(details.handle);
} }
flush(hostname) { flush(hostname) {
if ( hostname === '' ) { return; }
if ( hostname === '*' ) { return this.reset(); } if ( hostname === '*' ) { return this.reset(); }
for ( const hn of this.hostnameToDetails.keys() ) { for ( const hn of this.hostnameToDetails.keys() ) {
if ( hn.endsWith(hostname) === false ) { continue; } if ( hn.endsWith(hostname) === false ) { continue; }

View File

@ -148,7 +148,7 @@ const matchBucket = function(url, hostname, bucket, start) {
} }
bucket.push(directive); bucket.push(directive);
this.saveWhitelist(); this.saveWhitelist();
filteringBehaviorChanged({ hostname: targetHostname }); filteringBehaviorChanged({ hostname: targetHostname, direction: -1 });
return true; return true;
} }