Truly independent web browser
LibWebView: Keep the choices made for crash reports that failed to send
Andreas Kling22a562b3b465
diff --git a/Base/res/ladybird/about-pages/crashes.html b/Base/res/ladybird/about-pages/crashes.htmlindex e46753e7084..269b81bc66f 100644--- a/Base/res/ladybird/about-pages/crashes.html+++ b/Base/res/ladybird/about-pages/crashes.html@@ -446,6 +446,13 @@card.querySelector(".report-websites-title").classList.toggle("hidden", group.websites.length < 2);}+ function restoreChoices(card, group) {+ card.querySelector("textarea").value = group.note;+ card.querySelectorAll(".report-website input").forEach(input => {+ input.checked = group.includedWebsites.includes(input.value);+ });+ }+function reportsToSend(group, card) {const description = card.querySelector("textarea").value;const ticked = tickedWebsites(card);@@ -527,9 +534,11 @@// Moving a card takes the focus from its note, so one already in its place stays untouched.groups.forEach((group, index) => {- if (!cards.has(group.id)) cards.set(group.id, createCard(group.id));+ const isNewCard = !cards.has(group.id);+ if (isNewCard) cards.set(group.id, createCard(group.id));const card = cards.get(group.id);updateCard(card, group);+ if (isNewCard) restoreChoices(card, group);const current = reportsElement.children[index];if (current !== card) reportsElement.insertBefore(card, current ?? null);});diff --git a/Libraries/LibWebView/CrashReportOutbox.cpp b/Libraries/LibWebView/CrashReportOutbox.cppindex 06d8dd5a970..fbeb28dc9f0 100644--- a/Libraries/LibWebView/CrashReportOutbox.cpp+++ b/Libraries/LibWebView/CrashReportOutbox.cpp@@ -35,8 +35,9 @@ CrashReportOutbox::CrashReportOutbox(CrashReportStore& store)// Retries that all failed took a while, and the next report would only wait through the same ones. A report// the server turned down says nothing about the others.if (m_report_being_sent_was_retried) {- for (auto const& report : m_queue)- m_could_not_send.set(report.name, report.earlier_attempt);+ for (auto const& report : m_queue) {+ m_could_not_send.set(report.name, report.earlier_attempt.value_or(CrashReportReview::PreparedSubmission { {}, report.description, report.url }));+ }m_queue.clear();}@@ -70,8 +71,13 @@ Optional<String> CrashReportOutbox::send_from_review(CrashReportReview& review,return reason;if (auto* submission = review.submission()) {- submission->on_finished = [this, name] {- m_submissions_from_reviews.remove(name);+ submission->on_finished = [this, name, description, url, weak_review = review.make_weak_ptr<CrashReportReview>()] {+ auto finished_submission = m_submissions_from_reviews.take(name);++ // A review that is gone cannot offer to try again, so the report waits with what the user chose.+ if (!weak_review.ptr() && finished_submission.has_value() && !m_store.saved_report(name).is_error())+ m_could_not_send.set(name, CrashReportReview::PreparedSubmission { finished_submission.value()->prepared_manifest(), description, url });+reports_changed();};m_submissions_from_reviews.set(name, *submission);@@ -139,6 +145,14 @@ bool CrashReportOutbox::is_sending(ByteString const& name) const|| any_of(m_queue, [&](auto const& report) { return report.name == name; });}+Optional<CrashReportReview::PreparedSubmission> CrashReportOutbox::failed_attempt(ByteString const& name) const+{+ auto attempt = m_could_not_send.get(name);+ if (!attempt.has_value())+ return {};+ return attempt.value();+}+size_t CrashReportOutbox::waiting_report_count() const{auto names = m_store.pending_report_names();diff --git a/Libraries/LibWebView/CrashReportOutbox.h b/Libraries/LibWebView/CrashReportOutbox.hindex 7a8407263df..f3af1b67796 100644--- a/Libraries/LibWebView/CrashReportOutbox.h+++ b/Libraries/LibWebView/CrashReportOutbox.h@@ -49,6 +49,9 @@ public:bool is_sending(ByteString const& name) const;bool could_not_send(ByteString const& name) const { return m_could_not_send.contains(name); }+ // What the user chose for a report that could not be sent, so that sending it again can start from those choices.+ Optional<CrashReportReview::PreparedSubmission> failed_attempt(ByteString const& name) const;+// The reports that need the user, which leaves out those on their way.size_t waiting_report_count() const;diff --git a/Libraries/LibWebView/ReportSubmission.h b/Libraries/LibWebView/ReportSubmission.hindex eb03e46a6d0..4769838a3d9 100644--- a/Libraries/LibWebView/ReportSubmission.h+++ b/Libraries/LibWebView/ReportSubmission.h@@ -82,6 +82,9 @@ public:void start();void cancel();+ // What another attempt needs to count as the same submission, once this one has been prepared.+ ByteString prepared_manifest() const { return m_payload.has_value() ? m_payload->manifest : ByteString {}; }+Function<void(Stage)> on_progress;Function<void(ByteString const& manifest)> on_prepared;Function<void(String reason, u32 retry_number, u32 maximum_retries, u32 delay_seconds)> on_retry;diff --git a/Libraries/LibWebView/WebUI/CrashReportsUI.cpp b/Libraries/LibWebView/WebUI/CrashReportsUI.cppindex 29606973d3e..fa89569f65a 100644--- a/Libraries/LibWebView/WebUI/CrashReportsUI.cpp+++ b/Libraries/LibWebView/WebUI/CrashReportsUI.cpp@@ -141,10 +141,18 @@ void CrashReportsUI::load_reports()JsonArray serialized_names;bool is_sending = false;bool could_not_send = false;+ String note;+ JsonArray included_websites;for (auto const& name : group.names) {serialized_names.must_append(String::from_utf8_with_replacement_character(name));is_sending |= outbox.is_sending(name);could_not_send |= outbox.could_not_send(name);+ if (auto attempt = outbox.failed_attempt(name); attempt.has_value()) {+ if (note.is_empty())+ note = attempt->description;+ if (attempt->url.has_value())+ included_websites.must_append(*attempt->url);+ }}JsonObject serialized_group;@@ -171,6 +179,10 @@ void CrashReportsUI::load_reports()serialized_website_of_each_report.must_append(website.has_value() ? JsonValue { *website } : JsonValue {});serialized_group.set("websiteOfEachReport"sv, move(serialized_website_of_each_report));+ // A page opened after a failed attempt starts from the choices that were made for it.+ serialized_group.set("note"sv, note);+ serialized_group.set("includedWebsites"sv, move(included_websites));+serialized_group.set("isSending"sv, is_sending);serialized_group.set("couldNotSend"sv, could_not_send);serialized_groups.must_append(move(serialized_group));diff --git a/Tests/LibWebView/TestCrashReportSubmission.cpp b/Tests/LibWebView/TestCrashReportSubmission.cppindex 1c8cafced02..1b3177a454d 100644--- a/Tests/LibWebView/TestCrashReportSubmission.cpp+++ b/Tests/LibWebView/TestCrashReportSubmission.cpp@@ -241,5 +241,32 @@ TEST_CASE(crash_report_submission)}VERIFY(MUST(store.pending_report_names()).is_empty());+ // Reports still waiting behind one that failed after retries keep what the user chose for them.+ auto first_name = write_report(reports_directory, "2026-10-01T17-00-00Z-WebContent-abc123.txt"sv);+ auto second_name = write_report(reports_directory, "2026-10-01T18-00-00Z-WebContent-abc123.txt"sv);+ server.respond_with({ 503, "{}", {} });+ server.respond_with({ 400, "{}", {} });+ Vector<WebView::CrashReportOutbox::Report> reports;+ reports.append({ first_name, "I clicked a link"_string, "https://example.com/"_string });+ reports.append({ second_name, "I clicked a link"_string, "https://example.com/other"_string });+ outbox.send(move(reports));+ Core::EventLoop::current().spin_until([&] { return !outbox.is_sending(first_name) && !outbox.is_sending(second_name); });+ VERIFY(outbox.could_not_send(second_name));+ VERIFY(outbox.failed_attempt(second_name)->description == "I clicked a link"sv);+ VERIFY(outbox.failed_attempt(second_name)->url == "https://example.com/other"sv);++ // A report that fails after its review went away keeps what the user chose, and its submission ID.+ name = write_report(reports_directory, "2026-10-01T19-00-00Z-WebContent-abc123.txt"sv);+ {+ WebView::CrashReportReview departing_review { store };+ MUST(departing_review.open(name));+ server.respond_with({ 400, "{}", {} });+ VERIFY(!outbox.send_from_review(departing_review, "I closed the tab"_string, {}).has_value());+ }+ Core::EventLoop::current().spin_until([&] { return !outbox.is_sending(name); });+ VERIFY(outbox.could_not_send(name));+ VERIFY(outbox.failed_attempt(name)->description == "I closed the tab"sv);+ VERIFY(!outbox.failed_attempt(name)->manifest.is_empty());+outln("PASS: Crash reports reach the report server in the format it expects");}