Skip to content

Commit

Permalink
Unregister all scriptlets when disabling uBO on a specific site
Browse files Browse the repository at this point in the history
Related issue:
uBlockOrigin/uBlock-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.
  • Loading branch information
gorhill committed Jan 19, 2024
1 parent 5e9a7c6 commit 13dcd84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/js/scriptlet-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down Expand Up @@ -78,13 +81,15 @@ 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; }
this.hostnameToDetails.delete(hostname);
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; }
Expand Down
2 changes: 1 addition & 1 deletion src/js/ublock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 13dcd84

Please sign in to comment.