Skip to content

Commit

Permalink
Add argument to nowoif scriptlet
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gorhill committed Aug 17, 2020
1 parent a50c0a7 commit d544543
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/web_accessible_resources/window.open-defuser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
});
})();

0 comments on commit d544543

Please sign in to comment.