Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
350 views
in Technique[技术] by (71.8m points)

javascript - Why Do Ad Blockers Block Blobs?

Ad blockers block all new tabs opened if the content is a blob. I assume there's some reason behind this, but I can't figure it out. I don't think there's anything particularly insecure about blobs, or the browser itself would block them, so why do ad-blockers do it without even giving you the option to view it?

Here's a fiddle since it doesn't work right using Stack Overflows code snippet:

https://jsfiddle.net/Pharylon/dqjtha81/32/

const myString = "Hello World!";
const blob = new Blob([myString], {
  type: 'text/plain'
});
const fileURL = URL.createObjectURL(blob);
const myLink = document.getElementById("blob-link");
myLink.setAttribute("href", fileURL);
myLink.style.display = "block";

document.getElementById("my-div").innerText = myLink;
<p>
  The following won't open if you have an adblocker:
</p>

<a style="display: none" id="blob-link" href="" target="_blank">Click Me!</a>

<p>
  But you can manually copy/paste this and it'll work:
</p>

<div id="my-div"></div>

https://jsfiddle.net/Pharylon/dqjtha81/32/

Again, my question is why blockers do this. Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

That is the explanation in easylist.txt, a popular blocklist:

! Used with many websites to generate multiple popups
|blob:$popup
|data:text$popup
|dddata:text$popup

This is also referred to in the output of uBlock Origin, which uses easylist (among others):

enter image description here


For a concrete example, where blobs where used in combination with WebSockets to bypass all adblockers at that time, see the code snippet from the uBlock Origin issue (reformatted only):

AdDelivery.prototype.createWW = function() {
    var b = "self.onmessage=function(a){
    self.debug = " + this.debug + ';self.wsurl="
    ' + this.websocketURL + '
    ";self.initWS=

    function(b) {
        self.ws = new WebSocket(b);
        self.ws.onerror = function(c) {
            self.log(
                "Websocket error: " + c);
            postMessage(null)
        };
        self.ws.onopen = function(c) {
            self.log("Websocket connected")
        };
        self.ws.onmessage = function(c) {
            self.log("Websocket received msg.");
            postMessage(c.data)
        }
    };
    self.requestAds = function(b) {
        if (self.ws.readyState !== 1) {
            setTimeout(function() {
                self.log("Waiting for connection");
                self.requestAds(b)
            }, 100)
        } else {
            ws.send(b)
        }
    };
    self.log = function(b) {
        if (self.debug) {
            console.log(b)
        }
    };
    if (!self.ws) {
        self.initWS(self.wsurl);
        self.log("Initializing websocket")
    } else {
        self.log("Websocket already connected")
    }
    self.requestAds(a.data)
};
';
this.blob = new Blob([b], { type: "application/javascript" });
this.ww = new Worker(URL.createObjectURL(this.blob)); return };

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...