From f552f655cbdaf89e4f74a47772a4d896f12bb473 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 31 Aug 2024 12:36:20 -0400 Subject: [PATCH] Fix `prevent-window-open` for when logger is open Related discussion: https://github.com/uBlockOrigin/uBlock-discussions/discussions/906 --- assets/resources/scriptlets.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index 9d703997c..836a9ef2c 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -2885,7 +2885,7 @@ function noWindowOpenIf( pattern = pattern.slice(1); } const rePattern = safe.patternToRegex(pattern); - const autoRemoveAfter = parseInt(delay, 10) || 0; + const autoRemoveAfter = (parseFloat(delay) || 0) * 1000; const setTimeout = self.setTimeout; const createDecoy = function(tag, urlProp, url) { const decoyElem = document.createElement(tag); @@ -2895,9 +2895,10 @@ function noWindowOpenIf( decoyElem.style.setProperty('top','-1px', 'important'); decoyElem.style.setProperty('width','1px', 'important'); document.body.appendChild(decoyElem); - setTimeout(( ) => { decoyElem.remove(); }, autoRemoveAfter * 1000); + setTimeout(( ) => { decoyElem.remove(); }, autoRemoveAfter); return decoyElem; }; + const noopFunc = function(){}; proxyApplyFn('open', function open(target, thisArg, args) { const haystack = args.join(' '); if ( rePattern.test(haystack) !== targetMatchResult ) { @@ -2921,28 +2922,31 @@ function noWindowOpenIf( if ( typeof popup === 'object' && popup !== null ) { Object.defineProperty(popup, 'closed', { value: false }); } else { - const noopFunc = function open(){}; popup = new Proxy(self, { - get: function(target, prop) { + get: function(target, prop, ...args) { if ( prop === 'closed' ) { return false; } - const r = Reflect.get(...arguments); + const r = Reflect.get(target, prop, ...args); if ( typeof r === 'function' ) { return noopFunc; } - return target[prop]; + return r; }, - set: function() { - return Reflect.set(...arguments); + set: function(...args) { + return Reflect.set(...args); }, }); } if ( safe.logLevel !== 0 ) { popup = new Proxy(popup, { - get: function(target, prop) { - safe.uboLog(logPrefix, 'window.open / get', prop, '===', target[prop]); - return Reflect.get(...arguments); + get: function(target, prop, ...args) { + const r = Reflect.get(target, prop, ...args); + safe.uboLog(logPrefix, `popup / get ${prop} === ${r}`); + if ( typeof r === 'function' ) { + return (...args) => { return r.call(target, ...args); }; + } + return r; }, - set: function(target, prop, value) { - safe.uboLog(logPrefix, 'window.open / set', prop, '=', value); - return Reflect.set(...arguments); + set: function(target, prop, value, ...args) { + safe.uboLog(logPrefix, `popup / set ${prop} = ${value}`); + return Reflect.set(target, prop, value, ...args); }, }); }