diff --git a/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp b/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp index 9b40391b96f..5ff90f38f23 100644 --- a/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp +++ b/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace Web::IntersectionObserver { @@ -298,12 +299,13 @@ CSSPixelRect IntersectionObserver::root_intersection_rectangle() const document = &intersection_root.get>().cell()->document(); } if (m_document.has_value() && document->origin().is_same_origin(m_document->origin())) { - auto layout_node = intersection_root.visit([&](auto& elem) { return static_cast>(*elem)->layout_node(); }); - rect.inflate( - m_root_margin[0].to_px(*layout_node, rect.height()), - m_root_margin[1].to_px(*layout_node, rect.width()), - m_root_margin[2].to_px(*layout_node, rect.height()), - m_root_margin[3].to_px(*layout_node, rect.width())); + if (auto layout_node = intersection_root.visit([&](auto& node) -> GC::Ptr { return node->layout_node(); })) { + rect.inflate( + m_root_margin[0].to_px(*layout_node, rect.height()), + m_root_margin[1].to_px(*layout_node, rect.width()), + m_root_margin[2].to_px(*layout_node, rect.height()), + m_root_margin[3].to_px(*layout_node, rect.width())); + } } return rect;