diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp
index c18e3a8af4..1d690dc92e 100644
--- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp
@@ -15,6 +15,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -1907,11 +1908,16 @@ void HTMLDocumentParser::handle_text(HTMLToken& token)
auto the_script = document().take_pending_parsing_blocking_script({});
m_tokenizer.set_blocked(true);
- // FIXME: If the parser's Document has a style sheet that is blocking scripts
- // or the script's "ready to be parser-executed" flag is not set:
- // spin the event loop until the parser's Document has no style sheet
- // that is blocking scripts and the script's "ready to be parser-executed"
- // flag is set.
+ // If the parser's Document has a style sheet that is blocking scripts
+ // or the script's "ready to be parser-executed" flag is not set:
+ // spin the event loop until the parser's Document has no style sheet
+ // that is blocking scripts and the script's "ready to be parser-executed"
+ // flag is set.
+ if (m_document->has_a_style_sheet_that_is_blocking_scripts() || !script->is_ready_to_be_parser_executed()) {
+ main_thread_event_loop().spin_until([&] {
+ return !m_document->has_a_style_sheet_that_is_blocking_scripts() && script->is_ready_to_be_parser_executed();
+ });
+ }
if (the_script->failed_to_load())
return;