Improve compatibility with AdGuard's scriptlets

Related:
https://testcases.agrd.dev/Filters/scriptlet-rules/test-scriptlet-rules.html
This commit is contained in:
Raymond Hill 2023-07-11 18:25:21 -04:00
parent 41f1ca7d0d
commit ec06981965
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 10 additions and 6 deletions

View File

@ -1595,6 +1595,7 @@ builtinScriptlets.push({
aliases: [ aliases: [
'nosiif.js', 'nosiif.js',
'prevent-setInterval.js', 'prevent-setInterval.js',
'setInterval-defuser.js',
], ],
fn: noSetIntervalIf, fn: noSetIntervalIf,
dependencies: [ dependencies: [
@ -1619,7 +1620,7 @@ function noSetIntervalIf(
? console.log ? console.log
: undefined; : undefined;
const reNeedle = patternToRegex(needle); const reNeedle = patternToRegex(needle);
window.setInterval = new Proxy(window.setInterval, { self.setInterval = new Proxy(self.setInterval, {
apply: function(target, thisArg, args) { apply: function(target, thisArg, args) {
const a = String(args[0]); const a = String(args[0]);
const b = args[1]; const b = args[1];
@ -1637,7 +1638,7 @@ function noSetIntervalIf(
args[0] = function(){}; args[0] = function(){};
} }
} }
return target.apply(thisArg, args); return Reflect.apply(target, thisArg, args);
}, },
get(target, prop, receiver) { get(target, prop, receiver) {
if ( prop === 'toString' ) { if ( prop === 'toString' ) {
@ -1680,7 +1681,7 @@ function noSetTimeoutIf(
? console.log ? console.log
: undefined; : undefined;
const reNeedle = patternToRegex(needle); const reNeedle = patternToRegex(needle);
window.setTimeout = new Proxy(window.setTimeout, { self.setTimeout = new Proxy(self.setTimeout, {
apply: function(target, thisArg, args) { apply: function(target, thisArg, args) {
const a = String(args[0]); const a = String(args[0]);
const b = args[1]; const b = args[1];
@ -1698,7 +1699,7 @@ function noSetTimeoutIf(
args[0] = function(){}; args[0] = function(){};
} }
} }
return target.apply(thisArg, args); return Reflect.apply(target, thisArg, args);
}, },
get(target, prop, receiver) { get(target, prop, receiver) {
if ( prop === 'toString' ) { if ( prop === 'toString' ) {
@ -2226,6 +2227,9 @@ function disableNewtabLinks() {
builtinScriptlets.push({ builtinScriptlets.push({
name: 'cookie-remover.js', name: 'cookie-remover.js',
aliases: [
'remove-cookie.js',
],
fn: cookieRemover, fn: cookieRemover,
world: 'ISOLATED', world: 'ISOLATED',
dependencies: [ dependencies: [

View File

@ -174,7 +174,7 @@ export default new Map([
alias: 'widgets.outbrain.com/outbrain.js', alias: 'widgets.outbrain.com/outbrain.js',
} ], } ],
[ 'popads.js', { [ 'popads.js', {
alias: 'popads.net.js', alias: [ 'popads.net.js', 'prevent-popads-net.js' ],
data: 'text', data: 'text',
} ], } ],
[ 'popads-dummy.js', { [ 'popads-dummy.js', {

View File

@ -30,7 +30,7 @@
return oe(msg, src, line, col, error); return oe(msg, src, line, col, error);
} }
}.bind(); }.bind();
const throwMagic = function() { throw magic; }; const throwMagic = function() { throw new ReferenceError(magic); };
delete window.PopAds; delete window.PopAds;
delete window.popns; delete window.popns;
Object.defineProperties(window, { Object.defineProperties(window, {