I want to modify HTML code before DOM rendering. I have tried to use ajax as below:
window.stop();
var xhr = new XMLHttpRequest();
xhr.open('GET', window.location.href, true);
xhr.onload = function () {
var htmlcode = this.responseText;
... modify htmlcode ...
document.open();
document.write(htmlcode);
document.close();
}
xhr.send();
But it doesn't look very good when I inject it into "http://www.google.com". how can I do that using a chrome extension?