couldn't find something that perfectly handled large texts + large images, but i ended up with this, seems this gets it right, or nearly right, every single time:
iframe.addEventListener("load",function(){ // inlineSize, length, perspectiveOrigin, width let heightMax = 0; // this seems to work best with images... heightMax = Math.max(heightMax,iframe.contentWindow.getComputedStyle(iframe.contentWindow.document.body).perspectiveOrigin.split("px")[0]); // this seems to work best with text... heightMax = Math.max(heightMax,iframe.contentWindow.document.body.scrollHeight); // some large 1920x1080 images always gets a little bit off on firefox =/ const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; if(isFirefox && heightMax >= 900){ // grrr.. heightMax = heightMax + 100; } iframe.style.height = heightMax+"px"; //console.log(heightMax); });