Truly independent web browser
LibWebView+UI/Qt: Report website issues from the Help and page menus
Jelle Raaijmakersa14cc709b001
diff --git a/Documentation/WebCompatReports.md b/Documentation/WebCompatReports.mdnew file mode 100644index 00000000000..614b2168fa5--- /dev/null+++ b/Documentation/WebCompatReports.md@@ -0,0 +1,47 @@+# Web compatibility reports++A user who finds a website that Ladybird renders or runs incorrectly can report+it with **Report Website Issue...** in the Help menu or in the page's context+menu. The action is available for http and https pages that have not crashed,+in private windows too.++When the report starts, the browser freezes a frame of the visible page and dims+it. The user drags out the area that shows the problem, presses Enter or **Use+Visible Page** to take the whole frame, or picks **No Screenshot** to go without+one; Escape or **Cancel** abandons the report. The report then opens in a new+**Report Website Issue** tab next to the page. It asks what is wrong with the+website, which is required, and previews the selected area, which the user can+remove or retake from the same frame. Clicking the preview shows the screenshot+over the whole tab: in its actual size when the tab has room for it, and+otherwise fitted to the tab, where a click shows it in its actual size to drag+around in.++Reports always include the page URL, the user agent, the viewport size in CSS+pixels, the device pixel ratio and zoom level, and the Ladybird version,+platform, architecture, git commit and build configuration. The page's layout+tree, stacking context tree and display list are dumped when the report starts.+They are only included when the user checks **Include layout and painting+information**, because they contain text from the page and can contain personal+information; dumps larger than 8 MiB are cut off and say so. These dumps only+cover the top-level document, not its iframes. **View full report** shows the+diagnostics text in the tab, exactly as it would be sent.++The report is sent to the same report server as [crash reports](CrashReports.md),+as a `web_compat` report with a `webcompat-diagnostics.txt` attachment and, when+included, a `screenshot.png`. Screenshots are shrunk until they fit within 8+million pixels and 8 MiB. Sending retries transient failures, and **Try sending+again** after a failure resends the same submission. Until the report is sent,+**Cancel** stops sending it and returns to the review. Nothing about a web+compatibility report is written to disk: closing its tab discards an unsent+report, and a report on its way keeps being sent after the tab closes.++## Architecture++`WebCompatReport` in LibWebView describes the page from its view, requests its+dumps in one page info request, builds the diagnostics text and the manifest,+and sends them through `ReportSubmission`, which crash reports share.+The Qt UI takes the visible frame from the view's backing store, or from its+framebuffer when the backing store is GPU-shared, and presents+`ScreenshotSelectionOverlay` over the page, then `WebCompatReportReview` in a+blank tab, the way crash reports with no crash screen of their own are reviewed.+`ScreenshotViewer` shows the screenshot in full over that tab.diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cppindex a80e8106a26..4df69efc71f 100644--- a/Libraries/LibWebView/Application.cpp+++ b/Libraries/LibWebView/Application.cpp@@ -2713,6 +2713,12 @@ void Application::initialize_actions()});m_inspect_menu->add_action(*m_toggle_devtools_action);+ m_report_website_issue_action = Action::create("Report Website Issue..."sv, ActionID::ReportWebsiteIssue, [this]() {+ if (auto view = active_web_view(); view.has_value())+ view->report_website_issue();+ });+ m_report_website_issue_action->set_enabled(false);+m_debug_menu = Menu::create("Debug"sv);m_debug_menu->set_visible(m_settings->config_variable_as_bool(ConfigVariableID::ShowAdvancedDebugMenu));m_debug_menu->add_action(Action::create("Dump Session History Tree"sv, ActionID::DumpSessionHistoryTree, debug_request("dump-session-history"sv)));@@ -2963,6 +2969,7 @@ void Application::update_actions_for_active_web_view(){update_bookmark_action_for_current_web_view();update_editing_history_actions();+ update_report_website_issue_action();}void Application::bookmarks_changed(Badge<ApplicationBookmarkStoreObserver>)@@ -3405,6 +3412,12 @@ void Application::inspect_indexed_database_objects(DevTools::TabDescription consview->inspect_indexed_database_objects(host, move(names), move(options), move(on_complete));}+void Application::update_report_website_issue_action()+{+ auto view = active_web_view();+ m_report_website_issue_action->set_enabled(view.has_value() && view->can_report_website_issue());+}+void Application::update_editing_history_actions(){auto view = active_web_view();diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.hindex cfd256655d4..6e6fee447a1 100644--- a/Libraries/LibWebView/Application.h+++ b/Libraries/LibWebView/Application.h@@ -384,6 +384,9 @@ public:Menu& inspect_menu() { return *m_inspect_menu; }Action& view_source_action() { return *m_view_source_action; }+ Action& report_website_issue_action() { return *m_report_website_issue_action; }+ void update_report_website_issue_action();+Menu& debug_menu() { return *m_debug_menu; }FileDownloader& file_downloader() { return m_file_downloader; }@@ -712,6 +715,8 @@ private:RefPtr<Action> m_view_source_action;RefPtr<Action> m_toggle_devtools_action;+ RefPtr<Action> m_report_website_issue_action;+RefPtr<Menu> m_debug_menu;RefPtr<Action> m_show_line_box_borders_action;RefPtr<Action> m_show_caret_hit_test_debug_overlay_action;diff --git a/Libraries/LibWebView/Menu.h b/Libraries/LibWebView/Menu.hindex c5601d31666..a57db30cd1d 100644--- a/Libraries/LibWebView/Menu.h+++ b/Libraries/LibWebView/Menu.h@@ -49,6 +49,7 @@ enum class ActionID {TakeVisibleScreenshot,TakeFullScreenshot,+ ReportWebsiteIssue,ToggleVerticalTabsExpanded,diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cppindex 8b422f80fd8..22c7ca4a11d 100644--- a/Libraries/LibWebView/ViewImplementation.cpp+++ b/Libraries/LibWebView/ViewImplementation.cpp@@ -154,6 +154,7 @@ void ViewImplementation::set_url(URL::URL url)if (m_url != url) {m_url = move(url);update_bookmark_action();+ update_report_website_issue_action();if (auto page = traversable().display_page(); page && page->routed_connection())page->routed_connection()->update_audio_capture_permission();}@@ -1435,6 +1436,24 @@ void ViewImplementation::get_source()page().async_get_source();}+// Only a website the page is showing can be reported, so not a browser page or a page that crashed.+bool ViewImplementation::can_report_website_issue() const+{+ return (m_url.scheme() == "http"sv || m_url.scheme() == "https"sv) && !crash_overlay_active();+}++void ViewImplementation::report_website_issue()+{+ if (can_report_website_issue() && on_request_website_issue_report)+ on_request_website_issue_report();+}++void ViewImplementation::update_report_website_issue_action()+{+ m_report_website_issue_action->set_enabled(can_report_website_issue());+ Application::the().update_report_website_issue_action();+}+void ViewImplementation::inspect_dom_tree(){page().async_inspect_dom_tree();@@ -3644,6 +3663,7 @@ void ViewImplementation::set_crash_state(Optional<CrashState> state)auto active = state.has_value();m_crash_state = move(state);notify_content_blocking_changed();+ update_report_website_issue_action();if (on_crash_overlay_state_change)on_crash_overlay_state_change(active);}@@ -4001,6 +4021,11 @@ void ViewImplementation::initialize_context_menus()take_and_save_screenshot(ScreenshotType::Full);});+ m_report_website_issue_action = Action::create("Report Website Issue..."sv, ActionID::ReportWebsiteIssue, [this]() {+ report_website_issue();+ });+ m_report_website_issue_action->set_enabled(false);+// A URL from the context menu is the page's — a link's or an image's — so it's navigated to from the page, unless// the user selected it as text. Blink also starts a selected URL with no initiator (IDC_CONTENT_CONTEXT_GOTOURL).m_open_in_new_tab_action = Action::create("Open in New Tab"sv, ActionID::OpenInNewTab, [this]() {@@ -4155,6 +4180,7 @@ void ViewImplementation::initialize_context_menus()m_page_context_menu->add_action(*m_take_full_screenshot_action);m_page_context_menu->add_separator();m_page_context_menu->add_action(application.view_source_action());+ m_page_context_menu->add_action(*m_report_website_issue_action);m_link_context_menu = Menu::create("Link Context Menu"sv);m_link_context_menu->add_action(*m_look_up_selected_text_action);diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.hindex e39a41f6068..e43eed71004 100644--- a/Libraries/LibWebView/ViewImplementation.h+++ b/Libraries/LibWebView/ViewImplementation.h@@ -283,6 +283,9 @@ public:void get_source();+ bool can_report_website_issue() const;+ void report_website_issue();+void inspect_dom_tree();void inspect_storage(Web::StorageAPI::StorageEndpointType, u64 request_id);Optional<StorageSetResult> set_session_storage_item(Utf16String const& key, Utf16String const& value);@@ -490,6 +493,7 @@ public:Function<void()> on_before_browser_initiated_navigation;Function<void(URL::URL const&, URL::Origin const&, ExternalURLHandler const&, Function<void(bool)>)> on_request_external_url_confirmation;Function<void()> on_request_accept_dialog;+ Function<void()> on_request_website_issue_report;Function<void()> on_request_dismiss_dialog;Function<void(JsonObject)> on_received_dom_tree;Function<void(DOMNodeProperties)> on_received_dom_node_properties;@@ -708,6 +712,7 @@ protected:void update_bookmark_action();void initialize_context_menus();+ void update_report_website_issue_action();void handle_external_url(URL::URL, URL::Origin, bool has_transient_activation, Function<void()> on_handler_unavailable = {});void handle_external_url_from_user_input(URL::URL const&, Function<void()> on_handler_unavailable = {});void complete_external_url_request();@@ -803,6 +808,7 @@ protected:RefPtr<Action> m_take_visible_screenshot_action;RefPtr<Action> m_take_full_screenshot_action;+ RefPtr<Action> m_report_website_issue_action;RefPtr<Action> m_open_in_new_tab_action;RefPtr<Action> m_open_in_new_window_action;diff --git a/Tests/LibWebView/CMakeLists.txt b/Tests/LibWebView/CMakeLists.txtindex 64fd527dcff..6c655e1e899 100644--- a/Tests/LibWebView/CMakeLists.txt+++ b/Tests/LibWebView/CMakeLists.txt@@ -204,6 +204,13 @@ if (NOT WIN32)target_compile_definitions(TestPictureInPictureWindowLifetime PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")endif()+ add_executable(TestWebCompatReportPage TestWebCompatReportPage.cpp)+ add_dependencies(TestWebCompatReportPage ladybird_build_resource_files ${ladybird_helper_processes})+ target_link_libraries(TestWebCompatReportPage PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)+ if (APPLE)+ target_compile_definitions(TestWebCompatReportPage PRIVATE LADYBIRD_BINARY_PATH="$<TARGET_FILE_DIR:ladybird>")+ endif()+add_executable(TestShadowTreeTooltipsAndLinks TestShadowTreeTooltipsAndLinks.cpp)add_dependencies(TestShadowTreeTooltipsAndLinks ladybird_build_resource_files ${ladybird_helper_processes})target_link_libraries(TestShadowTreeTooltipsAndLinks PRIVATE AK LibCore LibDiff LibFileSystem LibGfx LibImageDecoders LibImageDecoderClient LibIPC LibJS LibMain LibRequests LibURL LibWeb LibWebView)@@ -424,6 +431,8 @@ if (BUILD_TESTING AND NOT WIN32)add_test(NAME TestPictureInPictureWindowLifetime COMMAND $<TARGET_FILE:TestPictureInPictureWindowLifetime>)set_tests_properties(TestPictureInPictureWindowLifetime PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})+ add_test(NAME TestWebCompatReportPage COMMAND $<TARGET_FILE:TestWebCompatReportPage>)+ set_tests_properties(TestWebCompatReportPage PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})add_test(NAME TestShadowTreeTooltipsAndLinks COMMAND $<TARGET_FILE:TestShadowTreeTooltipsAndLinks>)set_tests_properties(TestShadowTreeTooltipsAndLinks PROPERTIES TIMEOUT 60 ENVIRONMENT LADYBIRD_SOURCE_DIR=${LADYBIRD_SOURCE_DIR})diff --git a/Tests/LibWebView/TestWebCompatReportPage.cpp b/Tests/LibWebView/TestWebCompatReportPage.cppnew file mode 100644index 00000000000..09c0e2512d9--- /dev/null+++ b/Tests/LibWebView/TestWebCompatReportPage.cpp@@ -0,0 +1,101 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++#include <AK/LexicalPath.h>+#include <AK/Random.h>+#include <AK/ScopeGuard.h>+#include <LibCore/Directory.h>+#include <LibCore/Environment.h>+#include <LibCore/EventLoop.h>+#include <LibCore/Promise.h>+#include <LibCore/StandardPaths.h>+#include <LibFileSystem/FileSystem.h>+#include <LibGfx/SystemTheme.h>+#include <LibMain/Main.h>+#include <LibWebView/Application.h>+#include <LibWebView/HeadlessWebView.h>+#include <LibWebView/Utilities.h>+#include <LibWebView/WebCompatReport.h>++namespace {++class TestApplication : public WebView::Application {+ WEB_VIEW_APPLICATION(TestApplication)++public:+ explicit TestApplication(Optional<ByteString> ladybird_binary_path)+ : WebView::Application(move(ladybird_binary_path))+ {+ }++ virtual void create_platform_options(WebView::BrowserOptions& browser_options, WebView::RequestServerOptions&, WebView::WebContentOptions& web_content_options) override+ {+ browser_options.headless_mode = WebView::HeadlessMode::Test;+ browser_options.disable_sql_database = WebView::DisableSQLDatabase::Yes;+ web_content_options.is_test_mode = WebView::IsTestMode::Yes;+ }++ virtual bool should_coordinate_browser_process() const override { return false; }+};++}++// A web compatibility report describes the page as the view shows it, and dumps how the page was laid out and painted.+// Pages that are not websites cannot be reported.++ErrorOr<int> ladybird_main(Main::Arguments arguments)+{+ auto test_config_directory = ByteString::formatted("{}/Ladybird-TestWebCompatReportPage-{}", Core::StandardPaths::tempfile_directory(), generate_random_uuid());+ TRY(Core::Directory::create(test_config_directory, Core::Directory::CreateDirectories::Yes));+ auto cleanup_test_config_directory = ScopeGuard([&] {+ MUST(FileSystem::remove(test_config_directory, FileSystem::RecursionMode::Allowed));+ });+ MUST(Core::Environment::set("XDG_CONFIG_HOME"sv, test_config_directory, Core::Environment::Overwrite::Yes));++#if defined(LADYBIRD_BINARY_PATH)+ auto app = TRY(TestApplication::create(arguments, LADYBIRD_BINARY_PATH));+#else+ auto app = TRY(TestApplication::create(arguments, OptionalNone {}));+#endif++ auto theme_path = LexicalPath::join(WebView::s_ladybird_resource_root, "themes"sv, "Default.ini"sv);+ auto theme = TRY(Gfx::load_system_theme(theme_path.string()));++ auto view = WebView::HeadlessWebView::create(move(theme), { 800, 600 });++ size_t loads_finished = 0;+ view->on_load_finish = [&](auto const&) { ++loads_finished; };+ Core::EventLoop::current().spin_until([&]() { return loads_finished >= 1; });++ view->load_html("<!DOCTYPE html><div style=\"width: 100px; height: 50px; background: red\">Broken</div>"sv);+ Core::EventLoop::current().spin_until([&]() { return loads_finished >= 2; });++ auto page = WebView::WebCompatReport::describe_page(*view);+ VERIFY(page.url == view->url());+ VERIFY(page.viewport_size == Gfx::IntSize(800, 600));+ VERIFY(page.device_pixel_ratio == 1.);+ VERIFY(page.zoom_level == 1.);+ VERIFY(!page.user_agent.is_empty());++ VERIFY(!view->can_report_website_issue());+ auto requests = 0;+ view->on_request_website_issue_report = [&] { ++requests; };+ view->report_website_issue();+ VERIFY(requests == 0);++ auto dumps = TRY(WebView::WebCompatReport::request_page_dumps(*view)->await());+ auto layout_tree = dumps.find_byte_offset("Viewport <#document>"sv);+ auto stacking_context_tree = dumps.find_byte_offset("\nSC for Viewport"sv);+ auto display_list = dumps.find_byte_offset("\nDisplayList:\n"sv);+ VERIFY(layout_tree == 0u);+ VERIFY(stacking_context_tree.has_value() && *stacking_context_tree > 0);+ VERIFY(display_list.has_value() && *display_list > *stacking_context_tree);+ VERIFY(dumps.bytes_as_string_view().substring_view(0, *stacking_context_tree).contains("Broken"sv));+ VERIFY(dumps.bytes_as_string_view().substring_view(*display_list).contains("FillRect"sv));++ outln("PASS: Web compatibility reports describe and dump the page the view shows");+ return 0;+}diff --git a/UI/Qt/Application.cpp b/UI/Qt/Application.cppindex 8d491cdf89e..7e2c8ef9220 100644--- a/UI/Qt/Application.cpp+++ b/UI/Qt/Application.cpp@@ -394,6 +394,8 @@ public:m_debug_menu = create_application_menu(*m_application_widget, application.debug_menu());m_help_menu = new QMenu("Help", m_application_widget);+ m_help_menu->addAction(create_application_action(*m_application_widget, application.report_website_issue_action(), IncludeActionIcon::No));+ m_help_menu->addSeparator();m_help_menu->addAction(create_application_action(*m_application_widget, application.open_about_page_action(), IncludeActionIcon::No));}diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cppindex 64bebb47637..702151f4651 100644--- a/UI/Qt/Tab.cpp+++ b/UI/Qt/Tab.cpp@@ -8,6 +8,7 @@#include <AK/kmalloc.h>#include <LibCore/EventLoop.h>+#include <LibCore/Promise.h>#include <LibURL/URL.h>#include <LibWakeLock/DisplaySleepInhibitor.h>#include <LibWebCommon/HTML/SelectedFile.h>@@ -818,6 +819,12 @@ Tab::Tab(BrowserWindow* window, Optional<WebView::CanonicalTraversable&> traversm_window->definitely_close_tab(index);};+ view().on_request_web_compat_report_review = [this](WebCompatReportCapture capture) {+ auto& tab = m_window->new_tab_from_url(URL::about_blank(), Web::HTML::ActivateTab::Yes, BrowserWindow::TabLocation::after_tab(*this));+ tab.view().review_web_compat_report(AK::move(capture));+ tab.enter_report_review(this, tr("Report Website Issue"));+ };+view().on_link_hover = [this](auto const& url) {m_hover_label->setText(qstring_from_ak_string(url.to_byte_string()));update_hover_label();@@ -1435,19 +1442,22 @@ QIcon Tab::tab_icon() constQString Tab::title() const{+ auto title = m_fixed_title.value_or(m_title);if (!WebView::Application::settings().config_variable_as_bool(WebView::ConfigVariableID::ShowWebContentProcessIDInTabTitle))- return m_title;+ return title;- return QString("%1 [%2]").arg(m_title).arg(view().page().client().pid());+ return QString("%1 [%2]").arg(title).arg(view().page().client().pid());}-// A tab opened only for a review shows it over a blank page, and closing it goes back to the tab it was opened from.-// That lasts until the user takes the tab somewhere else. The tab starts out loading about:blank, which is not somewhere-// else, but any page loaded after that is, about:blank included.-void Tab::enter_report_review(Tab* tab_to_activate_on_close)+// A tab opened only for a review shows it over a blank page, under the review's own title if it has one, and closing it+// goes back to the tab it was opened from. That lasts until the user takes the tab somewhere else. The tab starts out+// loading about:blank, which is not somewhere else, but any page loaded after that is, about:blank included.+void Tab::enter_report_review(Tab* tab_to_activate_on_close, Optional<QString> title){VERIFY(!m_report_review_navigation_listener.has_value());m_tab_to_activate_on_close = tab_to_activate_on_close;+ m_fixed_title = AK::move(title);+ update_tab_title();WebView::ViewImplementation::NavigationListener listener;listener.on_load_start = [this](URL::URL const& url) {@@ -1466,6 +1476,8 @@ void Tab::leave_report_review()view().leave_report_review();m_tab_to_activate_on_close = nullptr;+ m_fixed_title.clear();+ update_tab_title();// The view is still telling its listeners about this navigation, so the listener goes once it is done.QTimer::singleShot(0, this, [this, listener = m_report_review_navigation_listener.release_value()] {diff --git a/UI/Qt/Tab.h b/UI/Qt/Tab.hindex 82a0ee1c86f..30106e2f383 100644--- a/UI/Qt/Tab.h+++ b/UI/Qt/Tab.h@@ -122,7 +122,7 @@ public:void update_window_control_icons();void update_hover_label();- void enter_report_review(Tab* tab_to_activate_on_close);+ void enter_report_review(Tab* tab_to_activate_on_close, Optional<QString> title = {});bool url_is_hidden() const { return m_location_edit->url_is_hidden(); }void set_url_is_hidden(bool url_is_hidden) { m_location_edit->set_url_is_hidden(url_is_hidden); }@@ -216,6 +216,7 @@ private:Optional<WakeLock::DisplaySleepInhibitor> m_screen_display_sleep_inhibitor;BrowserWindow* m_window { nullptr };QString m_title;+ Optional<QString> m_fixed_title;Optional<u64> m_report_review_navigation_listener;bool m_has_loaded_report_review_page { false };HyperlinkLabel* m_hover_label { nullptr };diff --git a/UI/Qt/WebContentView.cpp b/UI/Qt/WebContentView.cppindex cad8e6e824d..958a23d5e2e 100644--- a/UI/Qt/WebContentView.cpp+++ b/UI/Qt/WebContentView.cpp@@ -6,6 +6,7 @@* SPDX-License-Identifier: BSD-2-Clause*/+#include <AK/Array.h>#include <AK/Assertions.h>#include <AK/ByteBuffer.h>#include <AK/Format.h>@@ -14,6 +15,7 @@#include <AK/Types.h>#include <AK/kmalloc.h>#include <LibCore/EventLoop.h>+#include <LibCore/Promise.h>#include <LibCore/Resource.h>#include <LibCore/Timer.h>#include <LibGfx/Bitmap.h>@@ -29,10 +31,14 @@#include <LibWebView/CrashReportStore.h>#include <LibWebView/PlatformColors.h>#include <LibWebView/Utilities.h>+#include <LibWebView/WebCompatReport.h>#include <LibWebView/WebContentClient.h>#include <UI/Qt/Application.h>#include <UI/Qt/CrashReportReviewWidget.h>#include <UI/Qt/ReportReview.h>+#include <UI/Qt/ScreenshotSelectionOverlay.h>+#include <UI/Qt/ScreenshotViewer.h>+#include <UI/Qt/WebCompatReportReview.h>#ifdef AK_OS_MACOS# include <UI/Qt/MacWindow.h>#endif@@ -299,11 +305,14 @@ WebContentView::WebContentView(QWidget* window, Optional<WebView::CanonicalTrave#endifon_ready_to_paint = [this]() {+ // Nothing of the page shows while an overlay covers it, which repaints the page once it goes away.+ if (!is_page_covered_by_overlay()) {#ifdef LADYBIRD_QT_USE_RHI_WIDGET- schedule_frame_damage_repaint();+ schedule_frame_damage_repaint();#else- schedule_repaint();+ schedule_repaint();#endif+ }emit ready_to_paint();};@@ -321,6 +330,10 @@ WebContentView::WebContentView(QWidget* window, Optional<WebView::CanonicalTraveshow_crash_report_review();};+ on_request_website_issue_report = [this] {+ start_web_compat_report();+ };+#ifdef AK_OS_MACOSon_request_dictionary_lookup = [this](auto const& lookup, auto position) {show_appkit_dictionary_lookup(*this, lookup, position);@@ -1133,13 +1146,13 @@ void WebContentView::paintEvent(QPaintEvent*)}#endif-Optional<QPixmap> WebContentView::tab_preview_pixmap(QSize const& maximum_size) const+// The page as the view currently shows it, in device pixels.+QImage WebContentView::visible_snapshot() const{auto paintable = current_paintable();- if (!paintable.has_value() || maximum_size.isEmpty())+ if (!paintable.has_value())return {};- QImage snapshot;if (auto bitmap = paintable->shared_image_buffer->bitmap_if_present()) {auto width = min(bitmap->width(), paintable->bitmap_size.width());auto height = min(bitmap->height(), paintable->bitmap_size.height());@@ -1147,15 +1160,23 @@ Optional<QPixmap> WebContentView::tab_preview_pixmap(QSize const& maximum_size)return {};QImage image(bitmap->scanline_u8(0), bitmap->width(), bitmap->height(), bitmap->pitch(), QImage::Format_RGB32);- snapshot = image.copy(0, 0, width, height);+ return image.copy(0, 0, width, height);}+#ifdef LADYBIRD_QT_USE_RHI_WIDGET- else {- // GPU-shared backing stores have no CPU-visible pixels, so grab the rendered widget instead.- snapshot = const_cast<WebContentView*>(this)->grabFramebuffer();- }+ // GPU-shared backing stores have no CPU-visible pixels, so grab the rendered widget instead.+ return const_cast<WebContentView*>(this)->grabFramebuffer();+#else+ return {};#endif+}++Optional<QPixmap> WebContentView::tab_preview_pixmap(QSize const& maximum_size) const+{+ if (maximum_size.isEmpty())+ return {};+ auto snapshot = visible_snapshot();if (snapshot.isNull())return {};@@ -1438,14 +1459,160 @@ void WebContentView::review_hidden_crash_report(ByteString const& report_name)// A tab opened only for a review lets go of what it showed over its page once the user takes the tab elsewhere.void WebContentView::leave_report_review(){+ QWidget* web_compat_report_overlays[] = { m_screenshot_selection_overlay, m_screenshot_viewer, m_web_compat_report_overlay };+ for (auto* overlay : web_compat_report_overlays) {+ if (!overlay)+ continue;+ overlay->hide();+ overlay->deleteLater();+ }+ m_web_compat_report_overlay = nullptr;+if (m_crash_overlay && !m_crash_overlay->isHidden() && !crash_overlay_active())set_crash_overlay_visible(false);+ schedule_repaint();+}++// The frame and the page's dumps are taken right away, so the report shows the page as it was when the user asked. The+// user selects what they saw on the page itself, and reviews the report in a tab of its own.+void WebContentView::start_web_compat_report()+{+ if (m_screenshot_selection_overlay)+ return;++ WebCompatReportCapture capture {+ .page = WebView::WebCompatReport::describe_page(*this),+ .frame = visible_snapshot(),+ .screenshot = {},+ .page_dumps = WebView::WebCompatReport::request_page_dumps(*this),+ };++ auto review = [this](WebCompatReportCapture capture) {+ if (on_request_web_compat_report_review)+ on_request_web_compat_report_review(AK::move(capture));+ };+ if (capture.frame.isNull()) {+ review(AK::move(capture));+ return;+ }++ auto frame = capture.frame;+ select_screenshot(frame, [review = AK::move(review), capture = AK::move(capture)](QImage screenshot) mutable {+ capture.screenshot = AK::move(screenshot);+ review(AK::move(capture));+ });+}++// The tab was opened only for the review, so no web content runs behind it, and leaving the review closes it.+void WebContentView::review_web_compat_report(WebCompatReportCapture capture)+{+ if (m_web_compat_report_overlay)+ return;++ m_web_compat_report_overlay = new PageOverlay(this);+ auto* column = &m_web_compat_report_overlay->column();++ auto* review = new WebCompatReportReview(AK::move(capture.page), AK::move(capture.screenshot), column);+ auto* column_layout = new QVBoxLayout(column);+ column_layout->setContentsMargins(0, 0, 0, 0);+ column_layout->addWidget(review);++ review->on_select_screenshot = [this, review = QPointer { review }, frame = AK::move(capture.frame)] {+ if (frame.isNull())+ return;+ select_screenshot(frame, [review](QImage screenshot) {+ if (!review)+ return;+ review->set_screenshot(AK::move(screenshot));+ review->setFocus(Qt::OtherFocusReason);+ });+ };+ review->on_view_screenshot = [this](QImage const& screenshot) {+ if (screenshot.isNull() || m_screenshot_viewer)+ return;++ auto* viewer = new ScreenshotViewer(screenshot, this);+ m_screenshot_viewer = viewer;+ auto focus_to_restore = show_transient_overlay(*viewer);+ viewer->on_closed = [this, viewer, focus_to_restore] {+ close_transient_overlay(*viewer, focus_to_restore);+ };+ };+ review->on_exit = [this] {+ if (on_close)+ on_close();+ };+ // The review is part of the overlay and cannot outlive it, even once leaving the review has let go of the overlay.+ review->on_report_text_visibility_change = [overlay = m_web_compat_report_overlay](bool visible) {+ overlay->set_fills_tab(visible);+ };++ capture.page_dumps+ ->when_resolved([review = QPointer { review }](String& page_dumps) {+ if (review)+ review->set_page_dumps(AK::move(page_dumps));+ })+ .when_rejected([](Error const& error) {+ warnln("Could not dump the page for a web compatibility report: {}", error);+ });++ m_web_compat_report_overlay->setGeometry(rect());+ m_web_compat_report_overlay->show();+ m_web_compat_report_overlay->raise();+ review->setFocus(Qt::OtherFocusReason);+ schedule_repaint();+}++// The selection shows a frame taken earlier, so the user selects what they saw, even while the page underneath changes.+void WebContentView::select_screenshot(QImage const& frame, Function<void(QImage)> on_selected)+{+ if (m_screenshot_selection_overlay)+ return;++ auto* overlay = new ScreenshotSelectionOverlay(frame, this);+ m_screenshot_selection_overlay = overlay;+ auto focus_to_restore = show_transient_overlay(*overlay);+ overlay->on_finished = [this, overlay, focus_to_restore, on_selected = AK::move(on_selected)](QImage screenshot) {+ close_transient_overlay(*overlay, focus_to_restore);+ on_selected(AK::move(screenshot));+ };+ overlay->on_canceled = [this, overlay, focus_to_restore] {+ close_transient_overlay(*overlay, focus_to_restore);+ };+}++// An overlay shown for a moment, such as to select or view a screenshot, hands the focus back once it is done.+QPointer<QWidget> WebContentView::show_transient_overlay(QWidget& overlay)+{+ auto focus_to_restore = QPointer { QApplication::focusWidget() };+ overlay.show();+ overlay.raise();+ overlay.setFocus(Qt::OtherFocusReason);+ schedule_repaint();+ return focus_to_restore;+}++void WebContentView::close_transient_overlay(QWidget& overlay, QPointer<QWidget> const& focus_to_restore)+{+ overlay.deleteLater();+ schedule_repaint();+ if (focus_to_restore)+ focus_to_restore->setFocus(Qt::OtherFocusReason);+}++Array<QWidget*, 4> WebContentView::overlays() const+{+ return { m_crash_overlay, m_web_compat_report_overlay, m_screenshot_selection_overlay, m_screenshot_viewer };}// Overlays are painted by Qt, underneath whatever presents the page on some platforms, which has to step aside for them.bool WebContentView::is_page_covered_by_overlay() const{- return m_crash_overlay && !m_crash_overlay->isHidden();+ for (auto* overlay : overlays()) {+ if (overlay && !overlay->isHidden())+ return true;+ }+ return false;}// A report of a crash with no crash screen of its own is reviewed in a blank tab opened for it.@@ -1508,8 +1675,10 @@ void WebContentView::resizeEvent(QResizeEvent* event)update_iosurface_layer_frame();#endif- if (m_crash_overlay)- m_crash_overlay->setGeometry(rect());+ for (auto* overlay : overlays()) {+ if (overlay)+ overlay->setGeometry(rect());+ }#ifdef LADYBIRD_QT_USE_RHI_WIDGETm_force_full_repaint = true;diff --git a/UI/Qt/WebContentView.h b/UI/Qt/WebContentView.hindex 66e508ecb55..ad5146065d2 100644--- a/UI/Qt/WebContentView.h+++ b/UI/Qt/WebContentView.h@@ -7,6 +7,7 @@#pragma once+#include <AK/Array.h>#include <AK/ByteString.h>#include <AK/Function.h>#include <AK/Optional.h>@@ -25,9 +26,12 @@#include <LibWebView/AccessibilityTreeManager.h>#include <LibWebView/BrowsingSession.h>#include <LibWebView/ViewImplementation.h>+#include <LibWebView/WebCompatReport.h>#include <LibWebCommon/Page/QueuedInputEvent.h>+#include <QImage>#include <QPixmap>+#include <QPointer>#include <QTimer>#include <QUrl>#include <QVariant>@@ -83,8 +87,17 @@ using WebContentViewBase = QWidget;class CrashOverlayUrlLabel;class CrashReportReviewWidget;class PageOverlay;+class ScreenshotSelectionOverlay;+class ScreenshotViewer;class SelectDropdown;+struct WebCompatReportCapture {+ WebView::WebCompatReport::Page page;+ QImage frame;+ QImage screenshot;+ NonnullRefPtr<Core::Promise<String>> page_dumps;+};+struct WebContentViewInitialState {WebView::IsPrivate is_private { WebView::IsPrivate::No };double maximum_frames_per_second { 60.0 };@@ -145,6 +158,9 @@ public:void cancel_mouse_press();void review_hidden_crash_report(ByteString const& report_name);void leave_report_review();+ void review_web_compat_report(WebCompatReportCapture);++ Function<void(WebCompatReportCapture)> on_request_web_compat_report_review;enum class PaletteMode {Default,@@ -192,6 +208,7 @@ private:};Optional<Paintable> current_paintable() const;+ QImage visible_snapshot() const;void update_viewport_size();void update_cursor(Gfx::Cursor cursor);@@ -221,6 +238,12 @@ private:void set_crash_overlay_visible(bool);void show_crash_report_review(Optional<ByteString> const& hidden_crash_report_name = {});+ void start_web_compat_report();+ void select_screenshot(QImage const& frame, Function<void(QImage)> on_selected);+ QPointer<QWidget> show_transient_overlay(QWidget&);+ void close_transient_overlay(QWidget&, QPointer<QWidget> const& focus_to_restore);++ Array<QWidget*, 4> overlays() const;bool is_page_covered_by_overlay() const;#if !defined(Q_OS_WIN)@@ -274,6 +297,10 @@ private:QWidget* m_crash_report_container { nullptr };CrashReportReviewWidget* m_crash_report_review { nullptr };+ QPointer<ScreenshotSelectionOverlay> m_screenshot_selection_overlay;+ QPointer<ScreenshotViewer> m_screenshot_viewer;+ PageOverlay* m_web_compat_report_overlay { nullptr };+#ifdef AK_OS_MACOSNativeTextEditingBindings m_native_text_editing_bindings;#endif