I was making a simple extension for Chrome to replace the first occurrence of string that I find in the body tag. I placed the following code inside content.js:
document.body.innerHTML = document.body.innerHTML.replace('Hello', 'Hi');
The issue is that there is a noticeable delay when original HTML is visible before the string is replaced. It is especially bad on larger web pages. Is there a way to execute it earlier that won't cause an error of body being null?