Skip to content

Commit

Permalink
Improve prevent-window-open scriptlet
Browse files Browse the repository at this point in the history
As discussed with filter list maintainers.
  • Loading branch information
gorhill committed Aug 30, 2024
1 parent ae5dc62 commit 7f11d62
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2885,10 +2885,8 @@ function noWindowOpenIf(
pattern = pattern.slice(1);
}
const rePattern = safe.patternToRegex(pattern);
let autoRemoveAfter = parseInt(delay);
if ( isNaN(autoRemoveAfter) ) {
autoRemoveAfter = -1;
}
const autoRemoveAfter = parseInt(delay, 10) || 0;
const setTimeout = self.setTimeout;
const createDecoy = function(tag, urlProp, url) {
const decoyElem = document.createElement(tag);
decoyElem[urlProp] = url;
Expand All @@ -2909,7 +2907,13 @@ function noWindowOpenIf(
return Reflect.apply(target, thisArg, args);
}
safe.uboLog(logPrefix, `Prevented (${args.join(', ')})`);
if ( autoRemoveAfter < 0 ) { return null; }
if ( delay === '' ) { return null; }
if ( decoy === 'blank' ) {
args[0] = 'about:blank';
const r = Reflect.apply(target, thisArg, args);
setTimeout(( ) => { r.close(); }, autoRemoveAfter);
return r;
}
const decoyElem = decoy === 'obj'
? createDecoy('object', 'data', ...args)
: createDecoy('iframe', 'src', ...args);
Expand Down

0 comments on commit 7f11d62

Please sign in to comment.