Install MutationObserver immediately
ClosedPublic

Authored by broulik on Jul 18 2018, 7:27 PM.

Details

Summary

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

Test Plan

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 :)

Diff Detail

Repository
R856 Plasma Browser Integration
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
broulik created this revision.Jul 18 2018, 7:27 PM
Restricted Application added a project: Plasma. · View Herald TranscriptJul 18 2018, 7:27 PM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
broulik requested review of this revision.Jul 18 2018, 7:27 PM
davidedmundson accepted this revision.Aug 1 2018, 10:23 AM
This revision is now accepted and ready to land.Aug 1 2018, 10:23 AM
This revision was automatically updated to reflect the committed changes.