I am trying to make block elements on a web page, but I want to do this before they are loaded. So for example, I could use
chrome.webRequest.onBeforeRequest.addListener(...);
And redirect / cancel the request. But I want to check the actual content of the request. What I'm doing right now is running XMLHttpRequest to load the url / object myself, checking the contents and blocking it if necessary. However, the main problem is that in reality not many objects are locked. This means that each object is loaded twice: once for "my verification" and once, after I said "well, you can load it."
How can I intercept the boot process so that I can check it on the fly and transfer data bytes, if allowed?
I hope you understand my question, thanks :-)
An example of how I am doing this right now:
function shall_be_blocked(info){ var xhr = new XMLHttpRequest(); xhr.open("GET", file, false); //... #load the file and inspect the bytes if (xhr.responseText=="block it") { return true; } return false; } chrome.webRequest.onBeforeRequest.addListener( function(info) { ret = shall_be_blocked(info); if (ret ...){return {cancel:true};}//loads the file once, as it is getting blocked return {};//loads the file twice }, {},["blocking"] );
javascript google-chrome block
mutilis
source share