summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-03-19 16:11:36 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-19 16:11:36 +0100
commitcbd343dcedfb061bc5c3c01c3caae78010cee219 (patch)
tree27fd884afd8df3193f62bdbbc358213d97ad448b /Userland/Libraries
parentc1f0d21bbefadaf2e8c9b295c74132c550d43e07 (diff)
downloadserenity-cbd343dcedfb061bc5c3c01c3caae78010cee219.zip
LibWeb: Only delay "load" event for script elements that load something
We shouldn't delay the load event for scripts that we're completely refusing to run anyway. Also, for scripts that have inline text content, we don't need to delay them either, as they will become ready before returning from "prepare script". This makes the "load" event finally fire on lots of websites, including Wikipedia. :^)
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp5
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h3
-rw-r--r--Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp4
3 files changed, 5 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
index 84d3736220..e2aa2a78c8 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.cpp
@@ -31,7 +31,7 @@ void HTMLScriptElement::set_parser_document(Badge<HTMLParser>, DOM::Document& do
m_parser_document = document;
}
-void HTMLScriptElement::begin_delaying_document_load_event(Badge<HTMLParser>, DOM::Document& document)
+void HTMLScriptElement::begin_delaying_document_load_event(DOM::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.
@@ -295,6 +295,9 @@ void HTMLScriptElement::prepare_script()
// Fetch a classic script given url, settings object, options, classic script CORS setting, and encoding.
auto request = LoadRequest::create_for_url_on_page(url, document().page());
+ if (parser_document)
+ begin_delaying_document_load_event(*parser_document);
+
ResourceLoader::the().load(
request,
[this, url](auto data, auto&, auto) {
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h
index a104e41ece..589773eae5 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLScriptElement.h
@@ -42,12 +42,11 @@ public:
void set_source_line_number(Badge<HTMLParser>, size_t source_line_number) { m_source_line_number = source_line_number; }
- void begin_delaying_document_load_event(Badge<HTMLParser>, DOM::Document&);
-
private:
void prepare_script();
void script_became_ready();
void when_the_script_is_ready(Function<void()>);
+ void begin_delaying_document_load_event(DOM::Document&);
WeakPtr<DOM::Document> m_parser_document;
WeakPtr<DOM::Document> m_preparation_time_document;
diff --git a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
index a2b41c4540..203fcf2456 100644
--- a/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
+++ b/Userland/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
@@ -2094,10 +2094,6 @@ void HTMLParser::handle_text(HTMLToken& token)
NonnullRefPtr<HTMLScriptElement> script = verify_cast<HTMLScriptElement>(current_node());
- // The document's "load" event is delayed until every script becomes ready.
- // See HTMLScriptElement internals for how readiness is determined.
- script->begin_delaying_document_load_event({}, *m_document);
-
(void)m_stack_of_open_elements.pop();
m_insertion_mode = m_original_insertion_mode;
// Let the old insertion point have the same value as the current insertion point.