1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-28 21:57:12 +02:00

Improve prevent-window-open scriptlet

As discussed with filter list maintainers.
This commit is contained in:
Raymond Hill 2024-08-30 10:25:39 -04:00
parent ae5dc6299e
commit 7f11d6216e
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -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;
@ -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);