diff --git a/src/web_accessible_resources/window.open-defuser.js b/src/web_accessible_resources/window.open-defuser.js index b89542a801606..54027d76a9742 100644 --- a/src/web_accessible_resources/window.open-defuser.js +++ b/src/web_accessible_resources/window.open-defuser.js @@ -27,7 +27,7 @@ if ( arg2 === '{{2}}' ) { arg2 = ''; } let arg3 = '{{3}}'; if ( arg3 === '{{3}}' ) { arg3 = ''; } - const log = arg3 !== '' + const log = /\blog\b/.test(arg3) ? console.log.bind(console) : ( ) => { }; const newSyntax = /^[01]?$/.test(arg1) === false; @@ -77,21 +77,25 @@ return target.apply(thisArg, args); } if ( autoRemoveAfter < 0 ) { return null; } - const decoy1 = createDecoy('iframe', 'src', url); - const decoy2 = createDecoy('object', 'data', url); - const popup = decoy1.contentWindow || decoy2.contentWindow; + const decoy = /\bobj\b/.test(arg3) + ? createDecoy('object', 'data', url) + : createDecoy('iframe', 'src', url); + let popup = decoy.contentWindow; Object.defineProperty(popup, 'closed', { value: false }); - if ( arg3 === '' ) { return popup; } - return new Proxy(popup, { - get: function(target, prop) { - log('window.open / get', prop, '===', target[prop]); - return target[prop]; - }, - set: function(target, prop, value) { - log('window.open / set', prop, '=', value); - target[prop] = value; - }, - }); + 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]; + }, + set: function(target, prop, value) { + log('window.open / set', prop, '=', value); + target[prop] = value; + }, + }); + } + return popup; } }); })();