If you have control over the iframe content , I strongly recommend using
ResizeObserver
Just insert the following at the end of srcdoc
attribute of iframe
,escape it if needed.
<script type="text/javascript">var ro = new ResizeObserver(entries => { for (let entry of entries) { const cr = entry.contentRect; // console.log(window.frameElement); window.frameElement.style.height =cr.height +30+"px"; }});ro.observe(document.body);</script>