Skip to content

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

Closed
@AdamWr

Description

@AdamWr

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions