diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index 603119593bdaf2e2f967db172afa44c06d1cca5d..432a088b6084bf45243ca83643812d9c650a0e4d 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 2e27eaa142edf82d6cc604768441affa5c57a1fd..54f2b3c1ba7877ca797d37dbab6614140f32589f 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 768475e4bc34ea25ca62328724c0973b4df35fd9..13257b39d9fc1fb688ff82a5d057aa14246cd9d9 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;
}