Sometimes certain websites will inject 3rd party scripts and DOM elements after the page has loaded (and sometimes at regular intervals). mutationObserver is used to observe the DOM over time for any new elements added and remove them if they match certain CSS selectors.
Is there a better implementation that would be more performant?
Explore whether or not it should be allowed to always observe, or whether it should disconnect automatically after a particular number of seconds (or any other event/circumstance).
Are there are any native window or document events that could trigger a reconnect if the DOM should be reviewed for new elements? Or would it be too late to observe what has already changed...
Measure any performance differences, and test on many different kinds of websites.
Why is
mutationObserver
used?Sometimes certain websites will inject 3rd party scripts and DOM elements after the page has loaded (and sometimes at regular intervals).
mutationObserver
is used to observe the DOM over time for any new elements added and remove them if they match certain CSS selectors.Is there a better implementation that would be more performant?
Review this StackOverflow answer and do some additional research and testing for ways to optimize how mutationObserver is used for best performance and least use of resources.
Explore whether or not it should be allowed to always observe, or whether it should disconnect automatically after a particular number of seconds (or any other event/circumstance).
Are there are any native
window
ordocument
events that could trigger a reconnect if the DOM should be reviewed for new elements? Or would it be too late to observe what has already changed...Measure any performance differences, and test on many different kinds of websites.