mutation-observer-iframe-script-module.html (603B)
1 <!doctype html> 2 <script> 3 new MutationObserver((mutations, observer) => { 4 mutations.forEach(({ addedNodes }) => { 5 addedNodes.forEach(node => { 6 if (node.nodeType == 1 && node.tagName == "SCRIPT") { 7 document.write("document.write body contents\n"); 8 document.close(); 9 window.parent.document.dispatchEvent(new CustomEvent("documentWriteDone")); 10 } 11 }); 12 }); 13 }).observe(document.documentElement, { childList: true, subtree: true }); 14 </script> 15 Initial body contents 16 <script type="module">window.parent.document.dispatchEvent(new CustomEvent("scriptRan"));</script>