diff --git a/Libraries/LibWeb/DOM/HTMLIFrameElement.cpp b/Libraries/LibWeb/DOM/HTMLIFrameElement.cpp
index 10b23822c5..e77f561689 100644
--- a/Libraries/LibWeb/DOM/HTMLIFrameElement.cpp
+++ b/Libraries/LibWeb/DOM/HTMLIFrameElement.cpp
@@ -82,4 +82,9 @@ void HTMLIFrameElement::load_src(const String& value)
m_hosted_frame->loader().load(url);
}
+const Document* HTMLIFrameElement::hosted_document() const
+{
+ return m_hosted_frame ? m_hosted_frame->document() : nullptr;
+}
+
}
diff --git a/Libraries/LibWeb/DOM/HTMLIFrameElement.h b/Libraries/LibWeb/DOM/HTMLIFrameElement.h
index 7520779af9..9e23ca88d3 100644
--- a/Libraries/LibWeb/DOM/HTMLIFrameElement.h
+++ b/Libraries/LibWeb/DOM/HTMLIFrameElement.h
@@ -40,6 +40,8 @@ public:
Frame* hosted_frame() { return m_hosted_frame; }
const Frame* hosted_frame() const { return m_hosted_frame; }
+ const Document* hosted_document() const;
+
private:
virtual void document_did_attach_to_frame(Frame&) override;
virtual void document_will_detach_from_frame(Frame&) override;
diff --git a/Libraries/LibWeb/Layout/LayoutFrame.cpp b/Libraries/LibWeb/Layout/LayoutFrame.cpp
index 94fe436125..d0c212123f 100644
--- a/Libraries/LibWeb/Layout/LayoutFrame.cpp
+++ b/Libraries/LibWeb/Layout/LayoutFrame.cpp
@@ -63,6 +63,13 @@ void LayoutFrame::render(RenderingContext& context)
{
LayoutReplaced::render(context);
+ auto* hosted_document = node().hosted_document();
+ if (!hosted_document)
+ return;
+ auto* hosted_layout_tree = hosted_document->layout_node();
+ if (!hosted_layout_tree)
+ return;
+
context.painter().save();
auto old_viewport_rect = context.viewport_rect();
@@ -70,7 +77,7 @@ void LayoutFrame::render(RenderingContext& context)
context.painter().translate(absolute_x(), absolute_y());
context.set_viewport_rect({ {}, node().hosted_frame()->size() });
- node().hosted_frame()->document()->layout_node()->render(context);
+ const_cast(hosted_layout_tree)->render(context);
context.set_viewport_rect(old_viewport_rect);
context.painter().restore();