Skip to content

Commit

Permalink
Invalidate browser's memory cache after using element picker
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gorhill committed Aug 9, 2019
1 parent aa70148 commit 5e1f4d7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/js/scriptlets/element-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ const userFilterFromCandidate = function(callback) {

// Cosmetic filter?
if ( v.startsWith('##') ) {
callback(hostname + v);
callback(hostname + v, true);
return;
}

Expand Down Expand Up @@ -1188,16 +1188,17 @@ const onDialogClicked = function(ev) {
// We have to exit from preview mode: this guarantees matching elements
// will be found for the candidate filter.
filterToDOMInterface.preview(false);
userFilterFromCandidate(filter => {
if ( !filter ) { return; }
userFilterFromCandidate((filter = undefined, isCosmetic = false) => {
if ( filter === undefined ) { return; }
vAPI.messaging.send(
'elementPicker',
{
what: 'createUserFilter',
autoComment: true,
filters: filter,
origin: window.location.origin,
pageDomain: window.location.hostname
pageDomain: window.location.hostname,
killCache: isCosmetic === false,
}
);
filterToDOMInterface.preview(rawFilterFromTextarea(), true);
Expand Down
6 changes: 6 additions & 0 deletions src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@
this.redirectEngine.freeze();
this.staticExtFilteringEngine.freeze();
this.selfieManager.destroy();

// https://www.reddit.com/r/uBlockOrigin/comments/cj7g7m/
// https://www.reddit.com/r/uBlockOrigin/comments/cnq0bi/
if ( options.killCache ) {
browser.webRequest.handlerBehaviorChanged();

This comment has been minimized.

Copy link
@gwarser

gwarser Dec 30, 2021

Contributor
}
};

const onLoaded = details => {
Expand Down

0 comments on commit 5e1f4d7

Please sign in to comment.