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(
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.