diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp index 5034660c55..39a017249f 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp @@ -31,6 +31,10 @@ HTMLScriptElement::~HTMLScriptElement() void HTMLScriptElement::set_parser_document(Badge, DOM::Document& document) { m_parser_document = document; + + // https://html.spec.whatwg.org/multipage/scripting.html#concept-script-script + // The user agent must delay the load event of the element's node document until the script is ready. + m_document_load_event_delayer.emplace(document); } void HTMLScriptElement::set_non_blocking(Badge, bool non_blocking) @@ -437,6 +441,7 @@ void HTMLScriptElement::prepare_script() void HTMLScriptElement::script_became_ready() { m_script_ready = true; + m_document_load_event_delayer.clear(); if (!m_script_ready_callback) return; m_script_ready_callback(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h index 6c8521b5f1..f034c4f0bd 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include @@ -63,6 +64,8 @@ private: Function m_script_ready_callback; RefPtr