Skip to content

Commit

Permalink
Improve googlesyndication-adsbygoogle — adsbygoogle.push
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWr committed Oct 21, 2022
1 parent 932ff82 commit 85a7677
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/redirects/googlesyndication-adsbygoogle.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export function GoogleSyndicationAdsByGoogle(source) {
for (const key of Object.keys(arg)) {
if (typeof arg[key] === 'function') {
try {
arg[key].call();
// https://github.com/AdguardTeam/Scriptlets/issues/252
// argument "{}" is needed to fix issue with undefined argument
arg[key].call(this, {});
} catch {
/* empty */
}
Expand Down
18 changes: 16 additions & 2 deletions tests/redirects/googlesyndication-adsbygoogle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,22 @@ test('Redirect testing', (assert) => {

assert.strictEqual(window.adsbygoogle.length, undefined, 'adsbygoogle.length check');
assert.strictEqual(window.adsbygoogle.push.length, 1, 'push.length check');
const pushCallback = () => {
assert.ok(true, 'callback was called');
const pushCallback = (arg) => {
try {
let check = false;
if (arg) {
check = true;
}
// Test for https://github.com/AdguardTeam/Scriptlets/issues/252
// If arg is not defined then error will be thrown
if (arg.whatever) {
arg.whatever = 1;
}
assert.strictEqual(check, true, 'callback was called');
} catch (error) {
const check = false;
assert.strictEqual(check, true, 'something went wrong');
}
};
const pushArg = {
test: 'test',
Expand Down

0 comments on commit 85a7677

Please sign in to comment.