Modern web pages use a disproportionately large share of system resources, so browser extensions should aim to add as little overhead as possible.
MutationObserver is designed for this. By specifying the
MutationObserver will give us every subtree that gets added. This is a simple and efficient solution for most cases, except one that happens to be pretty common: video player progress bars.
Every time the time marker moves,
MutationObserver dutifully invokes our code on it. In other words, our code gets called repeatedly to do nothing: the marker has already been darkened at page load, so any additional work is redundant. But doing nothing isn't the same as a no-op, since we still have to call
getComputedStyle (web developers should know that
getComputedStyle isn't cheap). If the video is an hour long, Nightlight would be running hundreds of times doing nothing useful.
In version 0.1.6, there is an option to whitelist domains where Nightlight should use
MutationObserver. However, it turns out a lot more sites dynamically modified the DOM than I thought, so version 0.1.7 changes the option to a blacklist.