diff --git a/Tests/LibWeb/Text/expected/WebAnimations/misc/animate-no-window.txt b/Tests/LibWeb/Text/expected/WebAnimations/misc/animate-no-window.txt
new file mode 100644
index 00000000000..aaecaf93c4a
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/WebAnimations/misc/animate-no-window.txt
@@ -0,0 +1 @@
+PASS (didn't crash)
diff --git a/Tests/LibWeb/Text/input/WebAnimations/misc/animate-no-window.html b/Tests/LibWeb/Text/input/WebAnimations/misc/animate-no-window.html
new file mode 100644
index 00000000000..f59a135a08c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/WebAnimations/misc/animate-no-window.html
@@ -0,0 +1,11 @@
+
+
+
diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp
index 8c75b7cee62..257987d39d2 100644
--- a/Userland/Libraries/LibWeb/DOM/Document.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Document.cpp
@@ -4185,8 +4185,9 @@ void Document::ensure_animation_timer()
m_animation_driver_timer->stop();
return;
}
-
- update_animations_and_send_events(window()->performance()->now());
+ auto* window_or_worker = dynamic_cast(&realm().global_object());
+ VERIFY(window_or_worker);
+ update_animations_and_send_events(window_or_worker->performance()->now());
}));
}