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:
parent
66cf6f0a14
commit
f552f655cb
@ -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);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user