paulshryock / Clean-Up-the-Web

Clean Up the Web removes certain HTML elements from websites which provide an unpleasant user experience.
Other
0 stars 0 forks source link

Optimize the way mutationObserver is used #2

Open paulshryock opened 3 years ago

paulshryock commented 3 years ago

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 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.