Don't wait for DOMContentLoaded as document.documentElement is always there (at least as far as HTML is concerned) and a website might dynamically create objects before that
davidedmundson fvogt lbeltrame
- Group Reviewers
- R856:183c91c6bb93: Install MutationObserver immediately
We intercept document.createElement so that when a website dynamically creates audio (or video) tags, we know about this. However, the JS environment the website sees is different from the one the content script sees, so we cannot just pass the element around as variable. Instead, we add it to the DOM which is then picked up by the mutation observer. We remove the element immediately afterwards as to not confuse the website.
When the website now dynamically creates an audio element before DOMContentLoaded, our mutation observer isn't installed yet and we miss this event.
Tested the https://googlechrome.github.io/samples/media-session/audio.html which works fine now
I didn't notice any slowdown caused by this but @lbeltrame please test with that heavy website you always use to verify it doesn't cause any problems for you :)