I'm trying to write a Chrome extension that would add a sibling to a certain HTML element — let's call it X — on a certain webpage (unfortunately you must be a privileged user to access that webpage, so I can't give a link).
Element X is created when the webpage first loads and then recreated, as part of a whole subtree rooted at one of its predecessors — let's call that predecessor Y — on certain circumstances.
I've been able to use Mutation Observers to detect the recreation of X via detecting changes in Y's child nodes.
But that's quite complicated, and possibly not very efficient, as element Y goes through many changes.
Is there a way to directly observe the creation and recreation of element X? It has a unique id, so there's no problem identifying it.
I'm open to using tools other than Mutation Observers, if there are better ways.
Thank you!