Skip to content

Commit

Permalink
AG-35022 Improve 'prevent-fetch' — set response.ok to false if respon…
Browse files Browse the repository at this point in the history
…se.type is opaque. #441

Squashed commit of the following:

commit 394781e
Author: jellizaveta <[email protected]>
Date:   Wed Oct 9 22:55:24 2024 +0300

    added comment

commit bc5ccc4
Merge: 93eb8c8 8872163
Author: jellizaveta <[email protected]>
Date:   Wed Oct 9 22:54:36 2024 +0300

    Merge branch 'fix/AG-35022' of ssh://bit.int.agrd.dev:7999/adguard-filters/scriptlets into fix/AG-35022

commit 8872163
Author: Slava Leleka <[email protected]>
Date:   Wed Oct 9 22:53:56 2024 +0300

    CHANGELOG.md edited online with Bitbucket

commit 93eb8c8
Author: jellizaveta <[email protected]>
Date:   Wed Oct 9 14:49:23 2024 +0300

    update compatibility-table

commit f45ffb7
Author: jellizaveta <[email protected]>
Date:   Wed Oct 9 22:24:54 2024 +0300

    update comment

commit 4424fc6
Author: jellizaveta <[email protected]>
Date:   Wed Oct 9 22:17:57 2024 +0300

    AG-35022 Improve  — set response.ok to false if response.type is opaque. #441
  • Loading branch information
jellizaveta committed Oct 10, 2024
1 parent 90eaf3d commit cef3485
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic

### Changed

- set response `ok` to `false` by `prevent-fetch` if response type is `opaque` [#441]
- improve `prevent-xhr` — modify response [#415]

[Unreleased]: https://github.com/AdguardTeam/Scriptlets/compare/v1.12.1...HEAD
[#451]: https://github.com/AdguardTeam/Scriptlets/issues/451
[#415]: https://github.com/AdguardTeam/Scriptlets/issues/415
[#441]: https://github.com/AdguardTeam/Scriptlets/issues/441

## [v1.12.1] - 2024-09-20

Expand Down
2 changes: 1 addition & 1 deletion scripts/compatibility-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
},
{
"adg": "prevent-window-open",
"ubo": "no-window-open-if.js (nowoif.js, prevent-window-open.js, window.open-defuser.js)"
"ubo": "prevent-window-open.js (nowoif.js, no-window-open-if.js, window.open-defuser.js)"
},
{
"adg": "remove-attr",
Expand Down
3 changes: 2 additions & 1 deletion src/helpers/noop-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const noopPromiseResolve = (

/**
* If responseType is opaque, then by default
* body is null, status is 0, statusText and url are empty strings,
* body is null, ok is false, status is 0, statusText and url are empty strings,
* as per https://fetch.spec.whatwg.org/#concept-filtered-response-opaque
* It's required to mock these properties to avoid adblock detection
* https://github.com/AdguardTeam/Scriptlets/issues/364
Expand All @@ -126,6 +126,7 @@ export const noopPromiseResolve = (
Object.defineProperties(response, {
body: { value: null },
status: { value: 0 },
ok: { value: false },
statusText: { value: '' },
url: { value: '' },
type: { value: responseType },
Expand Down
1 change: 1 addition & 0 deletions tests/scriptlets/prevent-fetch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ if (!isSupported) {
assert.strictEqual(response.status, 0, 'Response status is set to 0');
assert.strictEqual(response.statusText, '', 'Response statusText is set to empty string');
assert.strictEqual(response.body, null, 'Response body is set to null');
assert.strictEqual(response.ok, false, 'Response ok is set to false');
assert.strictEqual(window.hit, 'FIRED', 'hit function fired');
done();
});
Expand Down

0 comments on commit cef3485

Please sign in to comment.