为什么广告拦截器会阻止Blob?

时间:2018-07-10 19:30:50

标签: javascript adblock

如果内容是Blob,则广告阻止程序会阻止所有打开的新标签页。我认为这背后有一些原因,但我无法弄清楚。我不认为blob有什么特别不安全的东西,或者浏览器本身会阻止它们,所以为什么做广告拦截器甚至不给您选择查看它的机会?

这是一个小提琴,因为使用Stack Overflows代码片段无法正常工作:

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/

同样,我的问题是为什么阻止者这样做。谢谢!

1 个答案:

答案 0 :(得分:2)

这是流行的阻止列表easylist.txt中的解释:

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

uBlock Origin的输出中也提到了这一点,该输出使用了easylist(以及其他):

enter image description here


对于一个具体示例,其中blob与WebSockets结合使用到bypass all adblockers at that time,请参见uBlock Origin issue中的代码片段(仅重新格式化):

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 };