I'm trying to override document.write so i will be able to take the raw html parse it make some manipulations on the code and return the call. My entire process is async so it's needless to say that when document.write is called if the page has finished loading the document.write will erase the entire document, so i can't recall document.write. I've searched and found many discussions about that but almost every one of them is very very old so i can't find any good answer. my code for now is very basic:
const prevDocWrite = document.write;
document.write = function(str,patched) {
if(patched){
prevDocWrite.call(this, str);
}else{
Dom_Parser(str, context).then(newStr => {
prevDocWrite.call(this, newStr);
})};
};
I have added the "patched" part because i'm also calling document.write on my code so i call it like that document.write("str",true) and it will call the original document.write immediately.
I would really appreciate any help or ideas how to make this happen (other projects for reference will be great)
BTW i saw a lot of implementation using innerHtml but that's screwing up the <script>
tags:(
Thanks a LOT