diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index 603119593bd..432a088b608 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
@@ -513,7 +513,7 @@ void EventLoop::perform_a_microtask_checkpoint()
// FIXME: 8. Record timing info for microtask checkpoint.
}
-Vector> EventLoop::documents_in_this_event_loop_matching(auto callback) const
+Vector> EventLoop::documents_in_this_event_loop_matching(Function callback) const
{
Vector> documents;
for (auto& document : m_documents) {
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
index 2e27eaa142e..54f2b3c1ba7 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
@@ -73,6 +73,7 @@ public:
void unregister_document(Badge, DOM::Document&);
Vector> documents_in_this_event_loop() const;
+ [[nodiscard]] Vector> documents_in_this_event_loop_matching(Function callback) const;
Vector> same_loop_windows() const;
@@ -95,8 +96,6 @@ private:
virtual void visit_edges(Visitor&) override;
- [[nodiscard]] Vector> documents_in_this_event_loop_matching(auto callback) const;
-
void update_the_rendering();
Type m_type { Type::Window };
diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cpp
index 768475e4bc3..13257b39d9f 100644
--- a/Libraries/LibWeb/Page/Page.cpp
+++ b/Libraries/LibWeb/Page/Page.cpp
@@ -569,11 +569,9 @@ Vector> Page::documents_in_active_window() const
if (!top_level_traversable_is_initialized())
return {};
- auto documents = HTML::main_thread_event_loop().documents_in_this_event_loop();
- for (ssize_t i = documents.size() - 1; i >= 0; --i) {
- if (documents[i]->window() != top_level_traversable()->active_window())
- documents.remove(i);
- }
+ auto documents = HTML::main_thread_event_loop().documents_in_this_event_loop_matching([&](auto& document) {
+ return document.window() == top_level_traversable()->active_window();
+ });
return documents;
}