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-xhr scriptlet #199

Closed
AdamWr opened this issue Feb 25, 2022 · 3 comments
Closed

Improve prevent-xhr scriptlet #199

AdamWr opened this issue Feb 25, 2022 · 3 comments

Comments

@AdamWr
Copy link
Member

AdamWr commented Feb 25, 2022

There is a website - AdguardTeam/AdguardFilters#111383 which detects adblockers when googletagmanager.com/gtag/ (xmlhttprequest) is blocked.

Unfortunately, streamingcommunity.site#%#//scriptlet('prevent-xhr', 'googletagmanager.com') doesn't work correctly in this case and video player is broken.

If I'm not wrong, it's because website uses loadend event, so I guess that adding:

const loadEndEvent = new Event('loadend');
thisArg.dispatchEvent(loadEndEvent);

here:

setTimeout(() => {
const stateEvent = new Event('readystatechange');
thisArg.dispatchEvent(stateEvent);
const loadEvent = new Event('load');
thisArg.dispatchEvent(loadEvent);
}, 1);

should fixes this issue.

@ameshkov
Copy link
Member

Makes perfect sense, thank you!

More info on the XHR events:
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#events

@AdamWr
Copy link
Member Author

AdamWr commented Mar 9, 2022

By the way, maybe we could also add additional option to generate random responseText?

responseText: { value: '', writable: false },

As I recall, there was a website which was checking if responseText === "".

Steps to reproduce:

  1. Add this rule:
example.org#%#//scriptlet('prevent-xhr', 'pagead2.googlesyndication.com')
  1. Go to - https://example.org/
  2. Run this script:
(() => {
  function reqListener() {
    if (this.status !== 200 || this.responseText === "") {
      alert("adblock");
    } else {
      (() => {
        let video = '<iframe width="560" height="315" src="https://www.youtube.com/embed/Fy2rtb95QhY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
        let createDiv = document.createElement("div");
        document.body.appendChild(createDiv);
        createDiv.innerHTML = video;
      })();
    }
  }

  var oReq = new XMLHttpRequest();
  oReq.addEventListener("load", reqListener);
  oReq.open("GET", "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js");
  oReq.send();
})();

Alert will be displayed, because this.responseText returns "".
If pagead2.googlesyndication.com/pagead/js/adsbygoogle.js is not blocked then video player is loaded.

adguard pushed a commit that referenced this issue Mar 15, 2022
Merge in ADGUARD-FILTERS/scriptlets from fix/AG-13007 to release/v1.6

Squashed commit of the following:

commit 592df06
Merge: 7f2ba38 e724ea1
Author: Stanislav A <[email protected]>
Date:   Tue Mar 15 15:45:21 2022 +0300

    Merge branch 'release/v1.6' into fix/AG-13007

commit 7f2ba38
Author: Slava Leleka <[email protected]>
Date:   Tue Mar 15 13:15:15 2022 +0300

    typo edited online with Bitbucket

commit 3234f68
Author: Slava Leleka <[email protected]>
Date:   Tue Mar 15 13:15:04 2022 +0300

    typo edited online with Bitbucket

commit 0d746a5
Author: Stanislav A <[email protected]>
Date:   Tue Mar 15 13:10:19 2022 +0300

    update description & fix param usage

commit 006bb77
Author: Stanislav A <[email protected]>
Date:   Tue Mar 15 12:20:56 2022 +0300

    improve prevent-xhr scriptlet
adguard pushed a commit that referenced this issue Mar 24, 2022
* commit 'c06a8e539488e1ebfcf72c85a39a0ef5b9c028bb': (32 commits)
  AG-13382 update docs, validate noopjson
  push updated dist to github while release build. AG-13356
  remove tagcommander redirect AG-11959
  add readme info about testing ad debugging AG-12716
  add artifacts to scriptlets builds AG-12487
  improve set-constant scriptlet #65 AG-149
  improve prevent-xhr scriptlet #199 AG-13007
  improve googletagservices-gpt redirect #193 AG-12767
  add wcslog redirect #94 AG-3906
  improve ati-smarttag redirect #200 AG-13141
  improve json-prune scriptlet #171 AG-11879
  fix yandex metrika on avito #198 AG-12973
  improve metrika-yandex-tag redirect #189 AG-12550
  add prebid-ads redirect #190 AG-12558
  remove no-floc scriptlet AG-12869
  add noopjson redirect. AG-12796 #195
  Revert "revert tests and fix converter again"
  revert tests and fix converter again
  add conversion test for wildcard tld AG-12636
  add prevent-element-src-loading scriptlet #180 AG-12328
  ...
@uBlock-user
Copy link

@gorhill Need to do the same for no-xhr-if.js

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

6 participants