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

Fix 'prevent-fetch', 'prevent-xhr' — error on blocked request #334

Closed
Alex-302 opened this issue Jun 28, 2023 · 5 comments
Closed

Fix 'prevent-fetch', 'prevent-xhr' — error on blocked request #334

Alex-302 opened this issue Jun 28, 2023 · 5 comments

Comments

@Alex-302
Copy link
Member

Alex-302 commented Jun 28, 2023

The main problem - now this scriplet does not help if a request/domain is blocked by DNS filtering.
Affected more than 300 rules.

Steps to reproduce

  1. Disable Tracking Protection filter and add yext-pixel.com to user rules.
  2. Open https://clinics.vippetcare.com/al/birmingham/1928-montgomery-hwy./db089214-36a7-45a8-8f4e-6a14d7c5f17c
  3. Click View Pricing button
    => It does not work, because yext-pixel.com is blocked (in my case - by DNS).
  4. Add vippetcare.com#%#//scriptlet('prevent-fetch', 'www.yext-pixel.com')

Actual behavior

Scripltetdoes not intercept fetch request, and the button does not work.

Expected behavior

The rule must work like in 4.1.55, where no request when added that rule, and the button is not broken because of blocking request.

@Alex-302 Alex-302 added the bug Something isn't working label Jun 28, 2023
@Alex-302
Copy link
Member Author

Not sure if prevent-xhr has the same problem.

@Alex-302 Alex-302 changed the title prevent-fetch is broken 'prevent-fetch' is broken Jun 28, 2023
@Alex-302 Alex-302 changed the title 'prevent-fetch' is broken 'prevent-fetch' / 'prevent-xhr' are broken Jun 28, 2023
@AdamWr
Copy link
Member

AdamWr commented Jun 28, 2023

If I'm not wrong the problem is in this line:

const origResponse = await Reflect.apply(target, thisArg, args);

It tries to fetch a content, but request is blocked.

Simple test case:

  1. Add these rules:
||example.org^$xmlhttprequest
example.org#%#//scriptlet('prevent-fetch', '/')
  1. Go to - https://example.org/
  2. Run this script in console:
Code:
new Promise((resolve, reject) => {
  return fetch('/').then(response => {
    if (response.ok) {
        console.log('OK test');
      resolve(response)
    } else {
      reject(new Error('error'))
    }
  }, error => {
    reject(new Error(error.message))
  })
})

There should message in the console OK test, but with latest version of scriptlet it's blocked and there is an error.

adguard pushed a commit that referenced this issue Jun 29, 2023
Squashed commit of the following:

commit e055b3e
Author: Adam Wróblewski <adam@adguard.com>
Date:   Wed Jun 28 18:46:48 2023 +0200

    Add test with response.url

commit 4cea127
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Jun 28 19:30:41 2023 +0300

    Update a comment

commit e054ab2
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Jun 28 19:29:15 2023 +0300

    Update changelog

commit 7d43e43
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Jun 28 19:28:45 2023 +0300

    Add a comment with link to issue

commit 252040b
Author: Adam Wróblewski <adam@adguard.com>
Date:   Wed Jun 28 17:05:51 2023 +0200

    Update changelog

commit b0a4bc3
Author: Adam Wróblewski <adam@adguard.com>
Date:   Wed Jun 28 17:00:06 2023 +0200

    Fix issue with prevent-fetch and prevent-xhr
@adguard-bot adguard-bot changed the title 'prevent-fetch' / 'prevent-xhr' are broken Fix 'prevent-fetch', 'prevent-xhr' — error on blocked request Jul 18, 2023
@Alex-302
Copy link
Member Author

Another problem:
when all filters are turned off, and added technofino.in#%#//scriptlet('prevent-fetch', 'pagead2.googlesyndication.com'), the site detects ad blocker
https://www.technofino.in/community/threads/how-to-apply-for-hsbc-credit-card-for-non-serviceable-address-pincode.1991/

@AdamWr
Copy link
Member

AdamWr commented Jul 20, 2023

According to my tests, it should be fixed with latest changes.

@Alex-302
Copy link
Member Author

Yes, works fine with dev build.

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

4 participants