Skip to content

Commit

Permalink
Improve compatibility with AdGuard's scriptlets
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jul 11, 2023
1 parent 41f1ca7 commit ec06981
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,7 @@ builtinScriptlets.push({
aliases: [
'nosiif.js',
'prevent-setInterval.js',
'setInterval-defuser.js',
],
fn: noSetIntervalIf,
dependencies: [
Expand All @@ -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];
Expand All @@ -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' ) {
Expand Down Expand Up @@ -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];
Expand All @@ -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' ) {
Expand Down Expand Up @@ -2226,6 +2227,9 @@ function disableNewtabLinks() {

builtinScriptlets.push({
name: 'cookie-remover.js',
aliases: [
'remove-cookie.js',
],
fn: cookieRemover,
world: 'ISOLATED',
dependencies: [
Expand Down
2 changes: 1 addition & 1 deletion src/js/redirect-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
2 changes: 1 addition & 1 deletion src/web_accessible_resources/popads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit ec06981

Please sign in to comment.