Source:
<code>public void showCallbackHtml(String htmlOutput, Element parentElement) { initializeOutput(RmdChunkOutputUnit.TYPE_HTML); flushQueuedErrors(); if (StringUtil.isNullOrEmpty(htmlOutput)) return; final ChunkOutputFrame frame = new ChunkOutputFrame("Chunk Feedback"); add(frame); Element body = frame.getDocument().getBody(); Style bodyStyle = body.getStyle(); bodyStyle.setPadding(0, Unit.PX); bodyStyle.setMargin(0, Unit.PX); frame.loadUrlDelayed(htmlOutput, 250, new Command() { @Override public void execute() { DomUtils.fillIFrame(frame.getIFrame(), htmlOutput); DomUtils.forwardWheelEvent(frame.getIFrame().getContentDocument(), parentElement); Document anotherDoc = frame.getWindow().getDocument().getOwnerDocument(); int contentHeight = frame.getWindow().getDocument().getDocumentElement().getOffsetHeight(); frame.getElement().getStyle().setHeight(contentHeight, Unit.PX); frame.getElement().getStyle().setWidth(100, Unit.PCT); onHeightChanged(); Command handler = () -> { frame.getElement().getStyle().setHeight(0, Unit.PX); new Timer() { @Override public void run() { int newHeight = frame.getWindow().getDocument().getDocumentElement().getOffsetHeight(); frame.getElement().getStyle().setHeight(newHeight, Unit.PX); onHeightChanged(); } <START> }.schedule(50); <END> }; MutationObserver.Builder builder = new MutationObserver.Builder(handler); builder.attributes(true); builder.characterData(true); builder.childList(true); builder.subtree(true); MutationObserver observer = builder.get(); observer.observe(frame.getIFrame().getContentDocument().getBody()); } }); }</code><technical_language>This happening a WAN slow connection 50ms enough time for load (such guaranteed final height). wait for frame's load event</technical_language>

Target:
public void showCallbackHtml(String htmlOutput, Element parentElement) { initializeOutput(RmdChunkOutputUnit.TYPE_HTML); flushQueuedErrors(); if (StringUtil.isNullOrEmpty(htmlOutput)) return; final ChunkOutputFrame frame = new ChunkOutputFrame("Chunk Feedback"); add(frame); Element body = frame.getDocument().getBody(); Style bodyStyle = body.getStyle(); bodyStyle.setPadding(0, Unit.PX); bodyStyle.setMargin(0, Unit.PX); frame.loadUrlDelayed(htmlOutput, 250, new Command() { @Override public void execute() { DomUtils.fillIFrame(frame.getIFrame(), htmlOutput); DomUtils.forwardWheelEvent(frame.getIFrame().getContentDocument(), parentElement); int contentHeight = frame.getWindow().getDocument().getDocumentElement().getOffsetHeight(); frame.getElement().getStyle().setHeight(contentHeight, Unit.PX); frame.getElement().getStyle().setWidth(100, Unit.PCT); onHeightChanged(); Command handler = () -> { frame.getElement().getStyle().setHeight(0, Unit.PX); new Timer() { @Override public void run() { int newHeight = frame.getWindow().getDocument().getDocumentElement().getOffsetHeight(); frame.getElement().getStyle().setHeight(newHeight, Unit.PX); onHeightChanged(); } }.schedule(50); }; MutationObserver.Builder builder = new MutationObserver.Builder(handler); builder.attributes(true); builder.characterData(true); builder.childList(true); builder.subtree(true); MutationObserver observer = builder.get(); observer.observe(frame.getIFrame().getContentDocument().getBody()); } }); }