diff --git a/Tests/LibWeb/Text/expected/link-element-rel-preload-load-event.txt b/Tests/LibWeb/Text/expected/link-element-rel-preload-load-event.txt
new file mode 100644
index 00000000000..853dc1071a1
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/link-element-rel-preload-load-event.txt
@@ -0,0 +1,2 @@
+Got load event
+Got error event
diff --git a/Tests/LibWeb/Text/input/link-element-rel-preload-load-event.html b/Tests/LibWeb/Text/input/link-element-rel-preload-load-event.html
new file mode 100644
index 00000000000..8d197a7db2f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/link-element-rel-preload-load-event.html
@@ -0,0 +1,20 @@
+
+
diff --git a/Tests/LibWeb/Text/input/valid.css b/Tests/LibWeb/Text/input/valid.css
new file mode 100644
index 00000000000..14834ebb2cf
--- /dev/null
+++ b/Tests/LibWeb/Text/input/valid.css
@@ -0,0 +1 @@
+* { }
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
index db7dfe0d35a..a19773178ab 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2021, Andreas Kling
+ * Copyright (c) 2018-2023, Andreas Kling
* Copyright (c) 2021, the SerenityOS developers.
* Copyright (c) 2021, Sam Atkins
* Copyright (c) 2023, Srikavin Ramkumar
@@ -60,7 +60,7 @@ void HTMLLinkElement::inserted()
// FIXME: Respect the "as" attribute.
LoadRequest request;
request.set_url(document().parse_url(attribute(HTML::AttributeNames::href)));
- m_preload_resource = ResourceLoader::the().load_resource(Resource::Type::Generic, request);
+ set_resource(ResourceLoader::the().load_resource(Resource::Type::Generic, request));
} else if (m_relationship & Relationship::DNSPrefetch) {
ResourceLoader::the().prefetch_dns(document().parse_url(attribute(HTML::AttributeNames::href)));
} else if (m_relationship & Relationship::Preconnect) {
@@ -111,6 +111,8 @@ void HTMLLinkElement::parse_attribute(DeprecatedFlyString const& name, Deprecate
// https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet:fetch-and-process-the-linked-resource
// The appropriate times to fetch and process this type of link are:
if (
+ // AD-HOC: When the rel attribute changes
+ name == AttributeNames::rel ||
// - When the href attribute of the link element of an external resource link that is already browsing-context connected is changed.
name == AttributeNames::href ||
// - When the disabled attribute of the link element of an external resource link that is already browsing-context connected is set, changed, or removed.
@@ -128,16 +130,21 @@ void HTMLLinkElement::parse_attribute(DeprecatedFlyString const& name, Deprecate
void HTMLLinkElement::resource_did_fail()
{
dbgln_if(CSS_LOADER_DEBUG, "HTMLLinkElement: Resource did fail. URL: {}", resource()->url());
+ if (m_relationship & Relationship::Preload) {
+ dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error).release_value_but_fixme_should_propagate_errors());
+ }
}
void HTMLLinkElement::resource_did_load()
{
VERIFY(resource());
- VERIFY(m_relationship & (Relationship::Icon));
if (m_relationship & Relationship::Icon) {
resource_did_load_favicon();
m_document_load_event_delayer.clear();
}
+ if (m_relationship & Relationship::Preload) {
+ dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::load).release_value_but_fixme_should_propagate_errors());
+ }
}
void HTMLLinkElement::did_remove_attribute(DeprecatedFlyString const& attr)
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h
index 9afd820acd1..d7792925068 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2020, Andreas Kling
+ * Copyright (c) 2018-2023, Andreas Kling
* Copyright (c) 2021, the SerenityOS developers.
* Copyright (c) 2021, Sam Atkins
* Copyright (c) 2023, Srikavin Ramkumar
@@ -127,7 +127,6 @@ private:
};
};
- RefPtr m_preload_resource;
JS::GCPtr m_loaded_style_sheet;
Optional m_document_load_event_delayer;