From f8b8c9c4a4e80f783da125c42f688bd2186bc358 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Mon, 6 Jan 2025 11:09:47 +0000 Subject: [PATCH] LibWeb: Wait until ReadyState is complete before detaching HTML parser Previously, the DOM complete time was never being set, as the HTML parser was detached before `DocumentReadyState` was set to complete. --- Libraries/LibWeb/HTML/Parser/HTMLParser.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp index ce42769c1b3..3f36c6a6ac1 100644 --- a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp +++ b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp @@ -240,7 +240,6 @@ void HTMLParser::run(const URL::URL& url, HTMLTokenizer::StopAtInsertionPoint st m_document->set_source(MUST(String::from_byte_string(m_tokenizer.source()))); run(stop_at_insertion_point); the_end(*m_document, this); - m_document->detach_parser({}); } // https://html.spec.whatwg.org/multipage/parsing.html#the-end @@ -339,10 +338,14 @@ void HTMLParser::the_end(GC::Ref document, GC::Ptr pa })); // 9. Queue a global task on the DOM manipulation task source given the Document's relevant global object to run the following steps: - queue_global_task(HTML::Task::Source::DOMManipulation, *document, GC::create_function(document->heap(), [document] { + queue_global_task(HTML::Task::Source::DOMManipulation, *document, GC::create_function(document->heap(), [document, parser] { // 1. Update the current document readiness to "complete". document->update_readiness(HTML::DocumentReadyState::Complete); + // AD-HOC: We need to wait until the document ready state is complete before detaching the parser, otherwise the DOM complete time will not be set correctly. + if (parser) + document->detach_parser({}); + // 2. If the Document object's browsing context is null, then abort these steps. if (!document->browsing_context()) return;