From b98b2fc52becce75b858b0a6040328e291fdae29 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 18 Aug 2020 10:28:45 -0400 Subject: [PATCH] Slightly improve nowoif scriptlet Returns proxied self is no window object can be returned. --- .../window.open-defuser.js | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/web_accessible_resources/window.open-defuser.js b/src/web_accessible_resources/window.open-defuser.js index 3c3d40b36..7c4dccb63 100644 --- a/src/web_accessible_resources/window.open-defuser.js +++ b/src/web_accessible_resources/window.open-defuser.js @@ -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); }, }); }