1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-04 08:37:11 +02:00

Slightly improve nowoif scriptlet

Returns proxied self is no window object can
be returned.
This commit is contained in:
Raymond Hill 2020-08-18 10:28:45 -04:00
parent e3d06268da
commit b98b2fc52b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -80,18 +80,32 @@
const decoy = /\bobj\b/.test(arg3)
? createDecoy('object', 'data', url)
: createDecoy('iframe', 'src', url);
let popup = decoy.contentWindow || decoy;
Object.defineProperty(popup, 'closed', { value: false });
let popup = decoy.contentWindow;
if ( typeof popup === 'object' && popup !== null ) {
Object.defineProperty(popup, 'closed', { value: false });
} else {
const noopFunc = (function(){}).bind(self);
popup = new Proxy(self, {
get: function(target, prop) {
if ( prop === 'closed' ) { return false; }
const r = Reflect.get(...arguments);
if ( typeof r === 'function' ) { return noopFunc; }
return target[prop];
},
set: function() {
return Reflect.set(...arguments);
},
});
}
if ( /\blog\b/.test(arg3) ) {
popup = new Proxy(popup, {
get: function(target, prop) {
log('window.open / get', prop, '===', target[prop]);
if ( prop === 'closed' ) { return false; }
return target[prop];
return Reflect.get(...arguments);
},
set: function(target, prop, value) {
log('window.open / set', prop, '=', value);
target[prop] = value;
return Reflect.set(...arguments);
},
});
}