Skip to content

Commit

Permalink
AG-23263 Improve 'google-ima3'. #331
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 9db6334
Merge: 766dfb4 cba1d0f
Author: scripthunter7 <[email protected]>
Date:   Tue Jul 18 19:41:58 2023 +0200

    Merge branch 'master' into fix/AG-23263

commit 766dfb4
Author: scripthunter7 <[email protected]>
Date:   Tue Jul 18 19:30:11 2023 +0200

    change IMA tests

commit d01672f
Author: scripthunter7 <[email protected]>
Date:   Tue Jul 18 19:29:48 2023 +0200

    add comments

commit 30999fc
Merge: ece2529 3ef74ba
Author: Adam Wróblewski <[email protected]>
Date:   Tue Jul 18 17:58:35 2023 +0200

    Merge branch 'master' into fix/AG-23263

commit ece2529
Author: Adam Wróblewski <[email protected]>
Date:   Tue Jul 18 17:56:18 2023 +0200

    Improve 'google-ima3'
    Move window.google.ima.dai check at the end of GoogleIma3 function

commit d9e49ed
Author: Adam Wróblewski <[email protected]>
Date:   Mon Jul 17 17:36:57 2023 +0200

    Fix indentations in the test

commit 6f3dce4
Author: Adam Wróblewski <[email protected]>
Date:   Mon Jul 17 17:10:37 2023 +0200

    Improve google-ima3
    Do not overwrite google.ima if it was already set
  • Loading branch information
AdamWr committed Jul 18, 2023
1 parent cba1d0f commit b3843fc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- issue with overwriting `google.ima` value if it was already set
[#331](https://github.com/AdguardTeam/Scriptlets/issues/331)
- issue with printing unnecessary logs to the console in `log-addEventListener` scriptlet
[#335](https://github.com/AdguardTeam/Scriptlets/issues/335)
- error throwing in `prevent-fetch` and `prevent-xhr` scriptlets when a request is blocked
Expand Down
9 changes: 9 additions & 0 deletions src/redirects/google-ima3.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,15 @@ export function GoogleIma3(source) {
window.google = {};
}

// Workaround for https://github.com/AdguardTeam/Scriptlets/issues/331
// To avoid conflicts with the DAI SDK, we need to make sure that the
// google.ima.dai namespace is not overwritten.
// TODO: Later we should create a mock for the DAI SDK as well.
// See https://github.com/AdguardTeam/Scriptlets/issues/239
if (window.google.ima?.dai) {
ima.dai = window.google.ima.dai;
}

window.google.ima = ima;

hit(source);
Expand Down
27 changes: 27 additions & 0 deletions tests/redirects/google-ima3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,30 @@ test('Ima - run requestAds function twice', (assert) => {
done();
});
});

// https://github.com/AdguardTeam/Scriptlets/issues/331
test('Ima - check if DAI API is not discarded by the redirect', (assert) => {
// Define some dummy DAI API which cannot be discarded by the redirect
window.google = {
ima: {
// should be kept
dai: {
api: {
foo: 'bar',
},
},
// should be discarded
bar: 'foo',
},
};

runRedirect(name);

// check if DAI API is not discarded by the redirect
assert.ok(window.google.ima.dai, 'window.google.ima.dai exists');
assert.ok(window.google.ima.dai.api, 'window.google.ima.dai.api exists');
assert.strictEqual(window.google.ima.dai.api.foo, 'bar', 'window.google.ima.dai.api.foo is equal to "bar"');

// other properties should be discarded
assert.strictEqual(window.google.ima.bar, undefined, 'window.google.ima.bar is undefined');
});

0 comments on commit b3843fc

Please sign in to comment.