1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 12:57:57 +02:00

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() {
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; }

View File

@ -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;
}