1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-16 23:42:39 +01:00

Fix prevent-window-open for when logger is open

Related discussion:
https://github.com/uBlockOrigin/uBlock-discussions/discussions/906
This commit is contained in:
Raymond Hill 2024-08-31 12:36:20 -04:00
parent 66cf6f0a14
commit f552f655cb
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -2885,7 +2885,7 @@ function noWindowOpenIf(
pattern = pattern.slice(1); pattern = pattern.slice(1);
} }
const rePattern = safe.patternToRegex(pattern); const rePattern = safe.patternToRegex(pattern);
const autoRemoveAfter = parseInt(delay, 10) || 0; const autoRemoveAfter = (parseFloat(delay) || 0) * 1000;
const setTimeout = self.setTimeout; const setTimeout = self.setTimeout;
const createDecoy = function(tag, urlProp, url) { const createDecoy = function(tag, urlProp, url) {
const decoyElem = document.createElement(tag); const decoyElem = document.createElement(tag);
@ -2895,9 +2895,10 @@ function noWindowOpenIf(
decoyElem.style.setProperty('top','-1px', 'important'); decoyElem.style.setProperty('top','-1px', 'important');
decoyElem.style.setProperty('width','1px', 'important'); decoyElem.style.setProperty('width','1px', 'important');
document.body.appendChild(decoyElem); document.body.appendChild(decoyElem);
setTimeout(( ) => { decoyElem.remove(); }, autoRemoveAfter * 1000); setTimeout(( ) => { decoyElem.remove(); }, autoRemoveAfter);
return decoyElem; return decoyElem;
}; };
const noopFunc = function(){};
proxyApplyFn('open', function open(target, thisArg, args) { proxyApplyFn('open', function open(target, thisArg, args) {
const haystack = args.join(' '); const haystack = args.join(' ');
if ( rePattern.test(haystack) !== targetMatchResult ) { if ( rePattern.test(haystack) !== targetMatchResult ) {
@ -2921,28 +2922,31 @@ function noWindowOpenIf(
if ( typeof popup === 'object' && popup !== null ) { if ( typeof popup === 'object' && popup !== null ) {
Object.defineProperty(popup, 'closed', { value: false }); Object.defineProperty(popup, 'closed', { value: false });
} else { } else {
const noopFunc = function open(){};
popup = new Proxy(self, { popup = new Proxy(self, {
get: function(target, prop) { get: function(target, prop, ...args) {
if ( prop === 'closed' ) { return false; } if ( prop === 'closed' ) { return false; }
const r = Reflect.get(...arguments); const r = Reflect.get(target, prop, ...args);
if ( typeof r === 'function' ) { return noopFunc; } if ( typeof r === 'function' ) { return noopFunc; }
return target[prop]; return r;
}, },
set: function() { set: function(...args) {
return Reflect.set(...arguments); return Reflect.set(...args);
}, },
}); });
} }
if ( safe.logLevel !== 0 ) { if ( safe.logLevel !== 0 ) {
popup = new Proxy(popup, { popup = new Proxy(popup, {
get: function(target, prop) { get: function(target, prop, ...args) {
safe.uboLog(logPrefix, 'window.open / get', prop, '===', target[prop]); const r = Reflect.get(target, prop, ...args);
return Reflect.get(...arguments); 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) { set: function(target, prop, value, ...args) {
safe.uboLog(logPrefix, 'window.open / set', prop, '=', value); safe.uboLog(logPrefix, `popup / set ${prop} = ${value}`);
return Reflect.set(...arguments); return Reflect.set(target, prop, value, ...args);
}, },
}); });
} }