LibWeb: Act as if parsing stopped when generating an error document

The user agent now acts as if it has stopped parsing when creating a
document for inline content to display an error.
This commit is contained in:
Glenn Skrzypczak 2024-12-04 23:42:20 +01:00 committed by Tim Ledbetter
parent 6d7bb074fc
commit 88884c370c
Notes: github-actions[bot] 2024-12-07 08:39:00 +00:00

View file

@ -1171,10 +1171,18 @@ WebIDL::ExceptionOr<void> Navigable::populate_session_history_entry_document(
auto error_message = navigation_params.get<NullOrError>().value_or("Unknown error"sv);
auto error_html = load_error_page(entry->url(), error_message).release_value_but_fixme_should_propagate_errors();
entry->document_state()->set_document(create_document_for_inline_content(this, navigation_id, [error_html](auto& document) {
entry->document_state()->set_document(create_document_for_inline_content(this, navigation_id, [this, error_html](auto& document) {
auto parser = HTML::HTMLParser::create(document, error_html, "utf-8"sv);
document.set_url(URL::URL("about:error"));
parser->run();
// NOTE: Once the page has been set up, the user agent must act as if it had stopped parsing.
// FIXME: Directly calling parser->the_end results in a deadlock, because it waits for the warning image to load.
// However the response is never processed when parser->the_end is called.
// Queuing a global task is a workaround for now.
queue_a_task(Task::Source::Unspecified, HTML::main_thread_event_loop(), document, GC::create_function(heap(), [&document]() {
HTMLParser::the_end(document);
}));
}));
// 2. Make document unsalvageable given entry's document state's document and "navigation-failure".