I'm trying to make a javascript embed that will manipulate the page as it loads. The script is in the header, and I want it to be able to manipulate an element as soon as it can be found by document.querySelector. In other words, it needs to react to changes in the DOM while the document.readyState is "interactive", before it is "loaded". I can't use a timeout/interval because the document loading blocks until the full document is loaded, so if I put a timeout of 0ms it will not execute until the document.readyState is "loaded".
Are there any events that fire as elements are added to the DOM? I tried DOMNodeInserted, but it seems to only fire for elements added asynchronously after the document is loaded.
Lastly, this must be accomplished with only javascript; I do not have access to the html or server. The embed is going on other people's sites.