diff --git a/Base/res/ladybird/templates/error.html b/Base/res/ladybird/templates/error.html index 371d7613c58..d593cdc0a43 100644 --- a/Base/res/ladybird/templates/error.html +++ b/Base/res/ladybird/templates/error.html @@ -22,5 +22,6 @@ Warning

Failed to load @failed_url@

+

@error_message@

diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.cpp b/Userland/Libraries/LibWeb/HTML/Navigable.cpp index edb468260fd..b8fd9b9c5bc 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigable.cpp @@ -681,7 +681,7 @@ static WebIDL::ExceptionOr> create_navigation } // https://html.spec.whatwg.org/multipage/browsing-the-web.html#create-navigation-params-by-fetching -static WebIDL::ExceptionOr, JS::NonnullGCPtr>> create_navigation_params_by_fetching(JS::GCPtr entry, JS::GCPtr navigable, SourceSnapshotParams const& source_snapshot_params, TargetSnapshotParams const& target_snapshot_params, CSPNavigationType csp_navigation_type, Optional navigation_id) +static WebIDL::ExceptionOr create_navigation_params_by_fetching(JS::GCPtr entry, JS::GCPtr navigable, SourceSnapshotParams const& source_snapshot_params, TargetSnapshotParams const& target_snapshot_params, CSPNavigationType csp_navigation_type, Optional navigation_id) { auto& vm = navigable->vm(); auto& realm = navigable->active_window()->realm(); @@ -982,9 +982,14 @@ static WebIDL::ExceptionOr, JS // - locationURL is failure; or // - locationURL is a URL whose scheme is a fetch scheme // then return null. - if (response_holder->response()->is_network_error() || location_url.is_error() || (location_url.value().has_value() && Fetch::Infrastructure::is_fetch_scheme(location_url.value().value().scheme()))) { + if (response_holder->response()->is_network_error()) { + // AD-HOC: We pass the error message if we have one in NullWithError + if (response_holder->response()->network_error_message().has_value() && !response_holder->response()->network_error_message().value().is_null()) + return response_holder->response()->network_error_message().value(); + else + return Empty {}; + } else if (location_url.is_error() || (location_url.value().has_value() && Fetch::Infrastructure::is_fetch_scheme(location_url.value().value().scheme()))) return Empty {}; - } // 22. Assert: locationURL is null and response is not a network error. VERIFY(!location_url.value().has_value()); @@ -1039,7 +1044,7 @@ WebIDL::ExceptionOr Navigable::populate_session_history_entry_document( SourceSnapshotParams const& source_snapshot_params, TargetSnapshotParams const& target_snapshot_params, Optional navigation_id, - Variant, JS::NonnullGCPtr> navigation_params, + Navigable::NavigationParamsVariant navigation_params, CSPNavigationType csp_navigation_type, bool allow_POST, JS::SafeFunction completion_steps) @@ -1124,7 +1129,7 @@ WebIDL::ExceptionOr Navigable::populate_session_history_entry_document( } // 4. Otherwise, if navigationParams is null, then set failure to true. - if (navigation_params.has()) { + if (navigation_params.has() || navigation_params.has()) { failure = true; } @@ -1141,8 +1146,9 @@ WebIDL::ExceptionOr Navigable::populate_session_history_entry_document( if (failure) { // 1. Set entry's document state's document to the result of creating a document for inline content that doesn't have a DOM, given navigable, null, and navTimingType. // The inline content should indicate to the user the sort of error that occurred. - // FIXME: Add error message to generated error page - auto error_html = load_error_page(entry->url()).release_value_but_fixme_should_propagate_errors(); + auto error_message = navigation_params.has() ? navigation_params.get() : "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) { auto parser = HTML::HTMLParser::create(document, error_html, "utf-8"sv); document.set_url(URL::URL("about:error")); @@ -1427,7 +1433,7 @@ WebIDL::ExceptionOr Navigable::navigate(NavigateParams params) history_entry->set_document_state(document_state); // 7. Let navigationParams be null. - Variant, JS::NonnullGCPtr> navigation_params = Empty {}; + NavigationParamsVariant navigation_params = Empty {}; // FIXME: 8. If response is non-null: if (response) { diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.h b/Userland/Libraries/LibWeb/HTML/Navigable.h index fc7d7bae602..b209b990800 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigable.h +++ b/Userland/Libraries/LibWeb/HTML/Navigable.h @@ -52,6 +52,9 @@ class Navigable : public JS::Cell { public: virtual ~Navigable() override; + using NullWithError = StringView; + using NavigationParamsVariant = Variant, JS::NonnullGCPtr>; + ErrorOr initialize_navigable(JS::NonnullGCPtr document_state, JS::GCPtr parent); Vector> child_navigables() const; @@ -123,7 +126,7 @@ public: SourceSnapshotParams const& source_snapshot_params, TargetSnapshotParams const& target_snapshot_params, Optional navigation_id = {}, - Variant, JS::NonnullGCPtr> navigation_params = Empty {}, + NavigationParamsVariant navigation_params = Empty {}, CSPNavigationType csp_navigation_type = CSPNavigationType::Other, bool allow_POST = false, JS::SafeFunction completion_steps = [] {}); diff --git a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp index 6cd5a1b11b5..8da17333366 100644 --- a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp @@ -26,7 +26,7 @@ void set_chrome_process_executable_path(StringView executable_path) s_chrome_process_executable_path = MUST(String::from_utf8(executable_path)); } -ErrorOr load_error_page(URL::URL const& url) +ErrorOr load_error_page(URL::URL const& url, StringView error_message) { // Generate HTML error page from error template file // FIXME: Use an actual templating engine (our own one when it's built, preferably with a way to check these usages at compile time) @@ -34,6 +34,7 @@ ErrorOr load_error_page(URL::URL const& url) StringBuilder builder; SourceGenerator generator { builder }; generator.set("failed_url", url.to_byte_string()); + generator.set("error_message", escape_html_entities(error_message)); generator.append(template_file->data()); return TRY(String::from_utf8(generator.as_string_view())); } diff --git a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h index 855e307dee0..6caf7162e5d 100644 --- a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h +++ b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h @@ -17,7 +17,7 @@ static String s_chrome_process_executable_path {}; void set_chrome_process_command_line(StringView command_line); void set_chrome_process_executable_path(StringView executable_path); -ErrorOr load_error_page(URL::URL const&); +ErrorOr load_error_page(URL::URL const&, StringView error_message); ErrorOr load_file_directory_page(URL::URL const&);