diff --git a/Base/res/html/error.html b/Base/res/html/error.html index 280378e43d..ca8bf4f430 100644 --- a/Base/res/html/error.html +++ b/Base/res/html/error.html @@ -19,6 +19,5 @@ Warning

Failed to load @failed_url@

-

Error: @error@

diff --git a/Ladybird/Android/src/main/cpp/WebContentService.cpp b/Ladybird/Android/src/main/cpp/WebContentService.cpp index ea841f49c9..4893ad6f95 100644 --- a/Ladybird/Android/src/main/cpp/WebContentService.cpp +++ b/Ladybird/Android/src/main/cpp/WebContentService.cpp @@ -71,6 +71,7 @@ ErrorOr service_main(int ipc_socket, int fd_passing_socket) Web::Platform::FontPlugin::install(*new Ladybird::FontPlugin(is_layout_test_mode)); Web::set_resource_directory_url(TRY(String::formatted("file://{}/res", s_serenity_resource_root))); + Web::set_error_page_url(TRY(String::formatted("file://{}/res/html/error.html", s_serenity_resource_root))); Web::set_directory_page_url(TRY(String::formatted("file://{}/res/html/directory.html", s_serenity_resource_root))); TRY(Web::Bindings::initialize_main_thread_vm()); diff --git a/Ladybird/WebContent/main.cpp b/Ladybird/WebContent/main.cpp index 8176e72eed..e6633e9d53 100644 --- a/Ladybird/WebContent/main.cpp +++ b/Ladybird/WebContent/main.cpp @@ -97,6 +97,7 @@ ErrorOr serenity_main(Main::Arguments arguments) Web::Platform::FontPlugin::install(*new Ladybird::FontPlugin(is_layout_test_mode)); Web::set_resource_directory_url(TRY(String::formatted("file://{}/res", s_serenity_resource_root))); + Web::set_error_page_url(TRY(String::formatted("file://{}/res/html/error.html", s_serenity_resource_root))); Web::set_directory_page_url(TRY(String::formatted("file://{}/res/html/directory.html", s_serenity_resource_root))); TRY(Web::Bindings::initialize_main_thread_vm()); diff --git a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp index 9a89fa9c67..2a70a2dc83 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp +++ b/Userland/Libraries/LibWeb/DOM/DocumentLoading.cpp @@ -344,7 +344,8 @@ JS::GCPtr create_document_for_inline_content(JS::GCPtrrun(AK::URL("about:error")); + document->set_url(AK::URL("about:error")); + parser->run(); // 7. Return document. return document; diff --git a/Userland/Libraries/LibWeb/HTML/Navigable.cpp b/Userland/Libraries/LibWeb/HTML/Navigable.cpp index fd8573f135..b44dee852f 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigable.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -998,9 +999,8 @@ 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: Use SourceGenerator to produce error page from file:///res/html/error.html - // and display actual error from fetch response. - auto error_html = String::formatted("

Failed to load {}

"sv, entry->url).release_value_but_fixme_should_propagate_errors(); + // FIXME: Add error message to generated error page + auto error_html = load_error_page(entry->url).release_value_but_fixme_should_propagate_errors(); entry->document_state->set_document(create_document_for_inline_content(this, navigation_id, error_html)); // 2. Set entry's document state's document's salvageable to false. diff --git a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp index 21336494a6..c407d7e4dc 100644 --- a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.cpp @@ -26,6 +26,18 @@ void set_resource_directory_url(String resource_directory_url) s_resource_directory_url = resource_directory_url; } +static String s_error_page_url = "file:///res/html/error.html"_string; + +String error_page_url() +{ + return s_error_page_url; +} + +void set_error_page_url(String error_page_url) +{ + s_error_page_url = error_page_url; +} + static String s_directory_page_url = "file:///res/html/directory.html"_string; String directory_page_url() @@ -38,6 +50,20 @@ void set_directory_page_url(String directory_page_url) s_directory_page_url = directory_page_url; } +ErrorOr load_error_page(AK::URL const& url) +{ + // 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) + auto template_path = AK::URL::create_with_url_or_path(error_page_url().to_deprecated_string()).serialize_path(); + auto template_file = TRY(Core::File::open(template_path, Core::File::OpenMode::Read)); + auto template_contents = TRY(template_file->read_until_eof()); + StringBuilder builder; + SourceGenerator generator { builder }; + generator.set("resource_directory_url", resource_directory_url()); + generator.set("failed_url", url.to_deprecated_string()); + generator.append(template_contents); + return TRY(String::from_utf8(generator.as_string_view())); +} ErrorOr load_file_directory_page(LoadRequest const& request) { diff --git a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h index 4042aa209f..771380318a 100644 --- a/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h +++ b/Userland/Libraries/LibWeb/Loader/GeneratedPagesLoader.h @@ -6,16 +6,20 @@ #pragma once -#include #include +#include namespace Web { String resource_directory_url(); void set_resource_directory_url(String); +String error_page_url(); +void set_error_page_url(String); String directory_page_url(); void set_directory_page_url(String); +ErrorOr load_error_page(AK::URL const&); + ErrorOr load_file_directory_page(LoadRequest const&); }