The following code utilize DOM Mutation Event DOMNodeInserted
to detect the existence of the body
element and wrap its innerHTML
into a wr
The simple answer is that mutation observers are asynchronous. They are sent whenever the engine feels like it, some time after the change has taken place and in some cases after a great many changes have taken place. That may be long after a DOM mutation event listener would have notified you, but meanwhile the engine has been free to get its work done without having to constantly create and bubble events for every piddling DOM change.