From ec0698196563a8c8fb397364c0ac0eba20c38b47 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 11 Jul 2023 18:25:21 -0400 Subject: [PATCH] Improve compatibility with AdGuard's scriptlets Related: https://testcases.agrd.dev/Filters/scriptlet-rules/test-scriptlet-rules.html --- assets/resources/scriptlets.js | 12 ++++++++---- src/js/redirect-resources.js | 2 +- src/web_accessible_resources/popads.js | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index 4a16cd87b..c5b381867 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -1595,6 +1595,7 @@ builtinScriptlets.push({ aliases: [ 'nosiif.js', 'prevent-setInterval.js', + 'setInterval-defuser.js', ], fn: noSetIntervalIf, dependencies: [ @@ -1619,7 +1620,7 @@ function noSetIntervalIf( ? console.log : undefined; const reNeedle = patternToRegex(needle); - window.setInterval = new Proxy(window.setInterval, { + self.setInterval = new Proxy(self.setInterval, { apply: function(target, thisArg, args) { const a = String(args[0]); const b = args[1]; @@ -1637,7 +1638,7 @@ function noSetIntervalIf( args[0] = function(){}; } } - return target.apply(thisArg, args); + return Reflect.apply(target, thisArg, args); }, get(target, prop, receiver) { if ( prop === 'toString' ) { @@ -1680,7 +1681,7 @@ function noSetTimeoutIf( ? console.log : undefined; const reNeedle = patternToRegex(needle); - window.setTimeout = new Proxy(window.setTimeout, { + self.setTimeout = new Proxy(self.setTimeout, { apply: function(target, thisArg, args) { const a = String(args[0]); const b = args[1]; @@ -1698,7 +1699,7 @@ function noSetTimeoutIf( args[0] = function(){}; } } - return target.apply(thisArg, args); + return Reflect.apply(target, thisArg, args); }, get(target, prop, receiver) { if ( prop === 'toString' ) { @@ -2226,6 +2227,9 @@ function disableNewtabLinks() { builtinScriptlets.push({ name: 'cookie-remover.js', + aliases: [ + 'remove-cookie.js', + ], fn: cookieRemover, world: 'ISOLATED', dependencies: [ diff --git a/src/js/redirect-resources.js b/src/js/redirect-resources.js index 86ad161df..d2d0c4a7e 100644 --- a/src/js/redirect-resources.js +++ b/src/js/redirect-resources.js @@ -174,7 +174,7 @@ export default new Map([ alias: 'widgets.outbrain.com/outbrain.js', } ], [ 'popads.js', { - alias: 'popads.net.js', + alias: [ 'popads.net.js', 'prevent-popads-net.js' ], data: 'text', } ], [ 'popads-dummy.js', { diff --git a/src/web_accessible_resources/popads.js b/src/web_accessible_resources/popads.js index 4b6d0b609..df86e972f 100644 --- a/src/web_accessible_resources/popads.js +++ b/src/web_accessible_resources/popads.js @@ -30,7 +30,7 @@ return oe(msg, src, line, col, error); } }.bind(); - const throwMagic = function() { throw magic; }; + const throwMagic = function() { throw new ReferenceError(magic); }; delete window.PopAds; delete window.popns; Object.defineProperties(window, {