diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp index f9a9c7361c..cc0c6fb8cb 100644 --- a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp +++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp @@ -53,17 +53,17 @@ IntersectionObserver::IntersectionObserver(JS::Realm& realm, JS::GCPtrdocument().register_intersection_observer({}, *this); + m_document = node->document(); }); + m_document->register_intersection_observer({}, *this); } IntersectionObserver::~IntersectionObserver() = default; void IntersectionObserver::finalize() { - intersection_root().visit([this](auto& node) { - node->document().unregister_intersection_observer({}, *this); - }); + if (m_document) + m_document->unregister_intersection_observer({}, *this); } void IntersectionObserver::initialize(JS::Realm& realm) diff --git a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h index 83fbee91c0..a8ce7b333f 100644 --- a/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h +++ b/Userland/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.h @@ -83,6 +83,9 @@ private: // https://www.w3.org/TR/intersection-observer/#dom-intersectionobserver-observationtargets-slot Vector> m_observation_targets; + + // AD-HOC: This is the document where we've registered the IntersectionObserver. + WeakPtr m_document; }; }