Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve 'prevent-fetch' — set response.ok to false if response.type is opaque #441

Closed
AdamWr opened this issue Aug 7, 2024 · 0 comments

Comments

@AdamWr
Copy link
Member

AdamWr commented Aug 7, 2024

Steps to reproduce:

  1. Add this rule:
example.org#%#//scriptlet('prevent-fetch', 'googlesyndication', '', 'opaque')

2, Go to - https://example.org/
3. In browser console run:

(async () => {
  try {
    const response = await fetch('https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js', {
      mode: 'no-cors'
    });
    if (response.ok) {
      alert('adblock');
    }
  } catch (error) {
    alert('adblock');
  }
})();

Alert is displayed, because response.ok is true, but without ad blocker is false.
Adding ok: { value: false; } to:

Object.defineProperties(response, {
body: { value: null },
status: { value: 0 },
statusText: { value: '' },
url: { value: '' },
type: { value: responseType },
});

should fixes it.


This issue - #394 (comment) could be also fixed.

I think that the problem is that website overrides Object.defineProperties which is used by prevent-fetch.

@adguard-bot adguard-bot changed the title Improve prevent-fetch — set response.ok to false if response.type is opaque Improve 'prevent-fetch' — set response.ok to false if response.type is opaque Oct 7, 2024
@adguard-bot adguard-bot assigned jellizaveta and unassigned maximtop Oct 7, 2024
@slavaleleka slavaleleka added the enhancement Improvement of existent feature label Oct 7, 2024
adguard pushed a commit that referenced this issue Oct 10, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants