JSFiddle - React, Tailwind, and code Playground

HTML

<div id="foo">
  <!-- Iframe to be inserted in here -->
</div>

JavaScript

let iframe = document.createElement("iframe");
iframe.src = "https://en.wikipedia.org/";

document.getElementById("foo").appendChild(iframe);

iframe.onload = function() {
	iframe.style.height = "600px";//<-- Does work, why?
	resizeIframe(iframe);//<-- Does not work
  //iframe.style.height = iframe.contentWindow.document.body.scrollHeight + "px"; //<-- Does not work
}

function resizeIframe(obj) {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
  }