diff --git a/Tests/LibWeb/Text/expected/object-with-unsupported-type-in-data-attribute.txt b/Tests/LibWeb/Text/expected/object-with-unsupported-type-in-data-attribute.txt
new file mode 100644
index 0000000000..c9a1bf3b3e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/object-with-unsupported-type-in-data-attribute.txt
@@ -0,0 +1 @@
+ Fallback
diff --git a/Tests/LibWeb/Text/input/object-with-unsupported-type-in-data-attribute.html b/Tests/LibWeb/Text/input/object-with-unsupported-type-in-data-attribute.html
new file mode 100644
index 0000000000..b7a0b610bd
--- /dev/null
+++ b/Tests/LibWeb/Text/input/object-with-unsupported-type-in-data-attribute.html
@@ -0,0 +1,8 @@
+
+
+
+
diff --git a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp
index 73298cb435..bc84108de0 100644
--- a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp
+++ b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp
@@ -414,6 +414,30 @@ static WebIDL::ExceptionOr> load_media_document(
// be true for the Document.
}
+bool can_load_document_with_type(MimeSniff::MimeType const& type)
+{
+ if (type.is_html())
+ return true;
+ if (type.is_xml())
+ return true;
+ if (type.is_javascript()
+ || type.is_json()
+ || type.essence() == "text/css"_string
+ || type.essence() == "text/plain"_string
+ || type.essence() == "text/vtt"_string) {
+ return true;
+ }
+ if (type.essence() == "multipart/x-mixed-replace"_string)
+ return true;
+ if (type.is_image() || type.is_audio_or_video())
+ return true;
+ if (type.essence() == "application/pdf"_string || type.essence() == "text/pdf"_string)
+ return true;
+ if (type.essence() == "text/markdown"sv)
+ return true;
+ return false;
+}
+
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#loading-a-document
JS::GCPtr load_document(HTML::NavigationParams const& navigation_params)
{
diff --git a/Userland/Libraries/LibWeb/DOM/DocumentLoading.h b/Userland/Libraries/LibWeb/DOM/DocumentLoading.h
index 50294f0a4c..1fa2db3661 100644
--- a/Userland/Libraries/LibWeb/DOM/DocumentLoading.h
+++ b/Userland/Libraries/LibWeb/DOM/DocumentLoading.h
@@ -13,6 +13,7 @@ namespace Web {
bool build_xml_document(DOM::Document& document, ByteBuffer const& data, Optional content_encoding);
JS::GCPtr load_document(HTML::NavigationParams const& navigation_params);
+bool can_load_document_with_type(MimeSniff::MimeType const&);
// https://html.spec.whatwg.org/multipage/document-lifecycle.html#read-ua-inline
template
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp
index 810063c240..3c7c444c17 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp
@@ -7,6 +7,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -233,15 +234,6 @@ void HTMLObjectElement::resource_did_load()
run_object_representation_handler_steps(resource_type.has_value() ? resource_type->to_byte_string() : ByteString::empty());
}
-static bool is_xml_mime_type(StringView resource_type)
-{
- auto mime_type = MimeSniff::MimeType::parse(resource_type).release_value_but_fixme_should_propagate_errors();
- if (!mime_type.has_value())
- return false;
-
- return mime_type->is_xml();
-}
-
// https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-object-element:plugin-11
void HTMLObjectElement::run_object_representation_handler_steps(Optional resource_type)
{
@@ -252,8 +244,14 @@ void HTMLObjectElement::run_object_representation_handler_steps(Optionalstarts_with("image/"sv))) {
+ if (mime_type.has_value() && can_load_document_with_type(*mime_type) && (mime_type->is_xml() || !mime_type->is_image())) {
// If the object element's content navigable is null, then create a new child navigable for the element.
if (!m_content_navigable) {
MUST(create_new_child_navigable());