AdguardTeam / PopupBlocker

Popup blocking userscript
GNU Lesser General Public License v3.0
337 stars 31 forks source link

Feature/issues/5 #11

Closed theseanl closed 7 years ago

theseanl commented 7 years ago

It is an attempt to implement timing-based popup detection. It stores events having a fixed interface in an array, and window.open and other functions inspect this array to determine whether to allow calling itself or not.

In doing so, I refactored a previous source to isolate a module which systematically overrides browser apis, so that such overridden methods automatically reports to the array when it is called.

Exported methods from the module accepts a function of type ApplyHandler, which is a function that can be used as Proxy apply handlers.

To use proxy, it was necessary to wrap Function.prototype.call to guard from illegal invocation errors. For example, doing window.setTimeout.call(new Proxy(window,{}), function(){}, 100) may cause such errors.

However, doing it affects performance of any codes which use Function#apply, such as this, so it is dropped from release versions.

Exported methods from proxy.ts accepts an additional parameter of type ApplyOption, which can be used when specified to filter reported events.

It provides only one additional check currently (in https://github.com/AdguardTeam/PopupBlocker/blob/feature/issues/5/src/timeline/before/create.ts), but IMO an extensibility to add other checks and an ability to introspect what popup/popunder scripts do, which is almost impossible otherwise due to heavily obfuscated source codes justifies the increased complexity.

ameshkov commented 7 years ago

@seanl-adg IMPORTANT: don't merge it until we finish with the v2.0 release

sc0rp10 commented 7 years ago

@seanl-adg why do you need all of these build tools? in the one project you use: gulp, rollup, typescript, closure compiler and tsickle. Is all of these tools are required? Can we reduce complexity of build process? I cant call this gulpfile "clear & readable". Can you please explain all of these gulp tasks and move it to separate files in the tasks dir?