If you replace the documentElement with a non-html element and then set it to display: none we ignore it. ex. <iframe id="doc"></iframe> <script> var doc = document.getElementById('doc').contentDocument; var root = doc.implementation.createDocument().createElement('not-a-real-element'); doc.replaceChild(root, doc.documentElement); root.appendChild(document.createElement('style')).textContent = 'not-a-real-element { display: none }'; root.appendChild(document.createElement('p')).textContent = 'Should not be visible'; </script>
This is fixed by Bug 103475.