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 — modify response #415

Open
AdamWr opened this issue Apr 2, 2024 · 0 comments
Open

Improve prevent-xhr — modify response #415

AdamWr opened this issue Apr 2, 2024 · 0 comments
Assignees

Comments

@AdamWr
Copy link
Member

AdamWr commented Apr 2, 2024

Basically the same issue as here - #199 (comment), 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:

response: { value: modifiedResponse, writable: false },

if response is a text then it probably should be set to modifiedResponseText.

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