Scriptlets icon indicating copy to clipboard operation
Scriptlets copied to clipboard

Improve 'prevent-xhr' — modify response

Open AdamWr opened this issue 1 year ago • 0 comments

Basically the same issue as here - https://github.com/AdguardTeam/Scriptlets/issues/199#issuecomment-1063271758, but for response (currently only responseText is modified).

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 === "" || this.response === "") {
      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.response returns "". If pagead2.googlesyndication.com/pagead/js/adsbygoogle.js is not blocked then video player is loaded.

In this line: https://github.com/AdguardTeam/Scriptlets/blob/804c53527008e62ffcd296e3f36543c472b96fe5/src/scriptlets/prevent-xhr.js#L206 if response is a text then it probably should be set to modifiedResponseText.

AdamWr avatar Apr 02 '24 15:04 AdamWr