Skip to content

Commit 5e1f4d7

Browse files
committed
Invalidate browser's memory cache after using element picker
Related reports: - https://www.reddit.com/r/uBlockOrigin/comments/cj7g7m/ - https://www.reddit.com/r/uBlockOrigin/comments/cnq0bi/ The browser cache will be invalidated only when creating static network filter through the element picker. As per @gwarser's arguments in favor of implementing usage of webRequest.handlerBehaviorChanged(): https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest/handlerBehaviorChanged
1 parent aa70148 commit 5e1f4d7

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/js/scriptlets/element-picker.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ const userFilterFromCandidate = function(callback) {
10401040

10411041
// Cosmetic filter?
10421042
if ( v.startsWith('##') ) {
1043-
callback(hostname + v);
1043+
callback(hostname + v, true);
10441044
return;
10451045
}
10461046

@@ -1188,16 +1188,17 @@ const onDialogClicked = function(ev) {
11881188
// We have to exit from preview mode: this guarantees matching elements
11891189
// will be found for the candidate filter.
11901190
filterToDOMInterface.preview(false);
1191-
userFilterFromCandidate(filter => {
1192-
if ( !filter ) { return; }
1191+
userFilterFromCandidate((filter = undefined, isCosmetic = false) => {
1192+
if ( filter === undefined ) { return; }
11931193
vAPI.messaging.send(
11941194
'elementPicker',
11951195
{
11961196
what: 'createUserFilter',
11971197
autoComment: true,
11981198
filters: filter,
11991199
origin: window.location.origin,
1200-
pageDomain: window.location.hostname
1200+
pageDomain: window.location.hostname,
1201+
killCache: isCosmetic === false,
12011202
}
12021203
);
12031204
filterToDOMInterface.preview(rawFilterFromTextarea(), true);

src/js/storage.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,12 @@
468468
this.redirectEngine.freeze();
469469
this.staticExtFilteringEngine.freeze();
470470
this.selfieManager.destroy();
471+
472+
// https://www.reddit.com/r/uBlockOrigin/comments/cj7g7m/
473+
// https://www.reddit.com/r/uBlockOrigin/comments/cnq0bi/
474+
if ( options.killCache ) {
475+
browser.webRequest.handlerBehaviorChanged();
476+
}
471477
};
472478

473479
const onLoaded = details => {

0 commit comments

Comments
 (0)