Resize an iframe to fit its content

Assume that frame represents the iframe element.
frame.addEventListener('load', function () {
// Get the height of the content
const height = frame.contentDocument.body.scrollHeight;
// Set the height of iframe
frame.setAttribute('height', `${height}px`);
});

See also