From b3fa54a791ee5c8864d4fd0dea92ed6967d07a37 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 5 Jul 2025 10:21:22 +0100 Subject: [PATCH] LibWeb: Set origin of new document in `Document.parseHTMLUnsafe()` Previously, a crash would occur when accessing the origin of a document created with this method. --- Libraries/LibWeb/DOM/Document.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 237a21063f5..3342b93c62e 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -6330,6 +6330,10 @@ GC::Ref Document::parse_html_unsafe(JS::VM& vm, StringView html) // 4. Parse HTML from a string given document and compliantHTML. // FIXME: Use compliantHTML. document->parse_html_from_a_string(html); + // AD-HOC: Setting the origin to match that of the associated document matches the behavior of existing browsers. + auto& associated_document = as(realm.global_object()).associated_document(); + document->set_origin(associated_document.origin()); + // 5. Return document. return document; }