Skip to content

Commit

Permalink
Fix prevent-window-open for when logger is open
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Aug 31, 2024
1 parent 66cf6f0 commit f552f65
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 ) {
Expand All @@ -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);
},
});
}
Expand Down

0 comments on commit f552f65

Please sign in to comment.