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

Open
AdamWr opened this issue Aug 7, 2024 · 0 comments
Assignees

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.

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

3 participants