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. :^)
This commit is contained in:
Andreas Kling 2022-03-19 16:11:36 +01:00
parent c1f0d21bbe
commit cbd343dced
Notes: sideshowbarker 2024-07-17 17:07:07 +09:00
3 changed files with 5 additions and 7 deletions

View file

@ -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) {