From 7f11d6216eb866fdbec4c13d9766b76432908f4f Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 30 Aug 2024 10:25:39 -0400 Subject: [PATCH] Improve `prevent-window-open` scriptlet As discussed with filter list maintainers. --- assets/resources/scriptlets.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index a3196208d..9d703997c 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -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);