Skip to content

Commit 13dcd84

Browse files
committed
Unregister all scriptlets when disabling uBO on a specific site
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.
1 parent 5e9a7c6 commit 13dcd84

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/js/scriptlet-filtering.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ const contentScriptRegisterer = new (class {
4545
constructor() {
4646
this.hostnameToDetails = new Map();
4747
if ( browser.contentScripts === undefined ) { return; }
48-
onBroadcast(msg => {
48+
this.bc = onBroadcast(msg => {
4949
if ( msg.what !== 'filteringBehaviorChanged' ) { return; }
50-
if ( msg.direction > 0 ) { return; }
51-
if ( msg.hostname ) { return this.flush(msg.hostname); }
50+
const direction = msg.direction || 0;
51+
if ( direction > 0 ) { return; }
52+
if ( direction >= 0 && msg.hostname ) {
53+
return this.flush(msg.hostname);
54+
}
5255
this.reset();
5356
});
5457
}
@@ -78,13 +81,15 @@ const contentScriptRegisterer = new (class {
7881
return false;
7982
}
8083
unregister(hostname) {
84+
if ( hostname === '' ) { return; }
8185
if ( this.hostnameToDetails.size === 0 ) { return; }
8286
const details = this.hostnameToDetails.get(hostname);
8387
if ( details === undefined ) { return; }
8488
this.hostnameToDetails.delete(hostname);
8589
this.unregisterHandle(details.handle);
8690
}
8791
flush(hostname) {
92+
if ( hostname === '' ) { return; }
8893
if ( hostname === '*' ) { return this.reset(); }
8994
for ( const hn of this.hostnameToDetails.keys() ) {
9095
if ( hn.endsWith(hostname) === false ) { continue; }

src/js/ublock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const matchBucket = function(url, hostname, bucket, start) {
148148
}
149149
bucket.push(directive);
150150
this.saveWhitelist();
151-
filteringBehaviorChanged({ hostname: targetHostname });
151+
filteringBehaviorChanged({ hostname: targetHostname, direction: -1 });
152152
return true;
153153
}
154154

0 commit comments

Comments
 (0)