Skip to content

Improve 'prevent-xhr' — modify response #415

@AdamWr

Description

@AdamWr

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="proxy.php?url=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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions