Chrome extension: Block page items before access

后端 未结 3 717
时光说笑
时光说笑 2020-12-02 00:25

I am trying to do block items on a webpage but I want to do that, before they are loaded. So, e.g., I could use

chrome.webRequest.onBeforeRequest.addListener(

3条回答
  •  执笔经年
    2020-12-02 00:51

    I believe you can use arraybuffers to read the content in real-time.

    Here's an example of loading a file / page into a buffer;

    var oReq = new XMLHttpRequest();
    oReq.open("GET", "/myfile.png", true);
    oReq.responseType = "arraybuffer";
    
    oReq.onload = function (oEvent) {
      var arrayBuffer = oReq.response; // Note: not oReq.responseText
      if (arrayBuffer) {
        var byteArray = new Uint8Array(arrayBuffer);
        for (var i = 0; i < byteArray.byteLength; i++) {
          // do something with each byte in the array
        }
      }
    };
    
    oReq.send(null);
    

    This is a piece of code found on the XMLHttpRequest documentation page. Link.

提交回复
热议问题