I have found this particular test in WPT tests:
<script>
function myObserver(mutationsList) {
for (let mutation of mutationsList) {
for (let n of mutation.addedNodes) {
if (n.id === 'shadow') {
n.innerHTML = "<span id=replaced>This should be in <div>'s shadow root</span>";
}
}
}
}
var observer = new MutationObserver(myObserver);
observer.observe(document.body, { childList: true, subtree: true });
</script>
<div id=host>
<template id=shadow shadowroot=open>
<span id=toreplace>This should get removed</span>
<script></script> <!-- Ensure observer runs -->
</template>
</div>
Now the questions is about <script></script> <!-- Ensure observer runs --> -> how does this line of code ensures that observer runs?