I want a function of my choosing to run when a DOM element is added to the page. This is in the context of a browser extension, so the webpage runs independently of me and I cannot modify its source. What are my options here?
I guess that, in theory, I could just use setInterval() to continually search for the element’s presence and perform my action if the element is there, but I need a better approach.
Since mutation events were deprecated in 2012, and you have no control over the inserted elements because they are added by someone else’s code, your only option is to continuously check for them.
Once this function is called, it will run every 100 milliseconds, which is 1/10 (one tenth) of a second. Unless you need real-time element observation, it should be enough.