Skip to content

Commit d544543

Browse files
committed
Add argument to nowoif scriptlet
When a 3rd argument was provided, the scriplet would log information related to window popup operations, regardless of the value of the argument. The 3rd argument is now parsed in a formal manner. It is meant to be one or more space-separated tokens which are used to fine tune the behavior of the scriptlet. Tokens: log: Cause the scriptlet to log information regarding how window.open() is used by the page on which the scriptlet is used. Useful only to filter creators. obj: Use an `object` element instead of `iframe` element (default) as a decoy to be used in place of a popup window, when the page requires a valid `window` instance to be returned.
1 parent a50c0a7 commit d544543

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/web_accessible_resources/window.open-defuser.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
if ( arg2 === '{{2}}' ) { arg2 = ''; }
2828
let arg3 = '{{3}}';
2929
if ( arg3 === '{{3}}' ) { arg3 = ''; }
30-
const log = arg3 !== ''
30+
const log = /\blog\b/.test(arg3)
3131
? console.log.bind(console)
3232
: ( ) => { };
3333
const newSyntax = /^[01]?$/.test(arg1) === false;
@@ -77,21 +77,25 @@
7777
return target.apply(thisArg, args);
7878
}
7979
if ( autoRemoveAfter < 0 ) { return null; }
80-
const decoy1 = createDecoy('iframe', 'src', url);
81-
const decoy2 = createDecoy('object', 'data', url);
82-
const popup = decoy1.contentWindow || decoy2.contentWindow;
80+
const decoy = /\bobj\b/.test(arg3)
81+
? createDecoy('object', 'data', url)
82+
: createDecoy('iframe', 'src', url);
83+
let popup = decoy.contentWindow;
8384
Object.defineProperty(popup, 'closed', { value: false });
84-
if ( arg3 === '' ) { return popup; }
85-
return new Proxy(popup, {
86-
get: function(target, prop) {
87-
log('window.open / get', prop, '===', target[prop]);
88-
return target[prop];
89-
},
90-
set: function(target, prop, value) {
91-
log('window.open / set', prop, '=', value);
92-
target[prop] = value;
93-
},
94-
});
85+
if ( /\blog\b/.test(arg3) ) {
86+
popup = new Proxy(popup, {
87+
get: function(target, prop) {
88+
log('window.open / get', prop, '===', target[prop]);
89+
if ( prop === 'closed' ) { return false; }
90+
return target[prop];
91+
},
92+
set: function(target, prop, value) {
93+
log('window.open / set', prop, '=', value);
94+
target[prop] = value;
95+
},
96+
});
97+
}
98+
return popup;
9599
}
96100
});
97101
})();

0 commit comments

Comments
 (0)