diff --git a/Base/res/ladybird/inspector.css b/Base/res/ladybird/inspector.css index 40757992f5..8aad2d16e0 100644 --- a/Base/res/ladybird/inspector.css +++ b/Base/res/ladybird/inspector.css @@ -204,6 +204,14 @@ details > :not(:first-child) { color: cyan; } + .console-message { + color: lightskyblue; + } + + .console-warning { + color: orange; + } + .console-input { background-color: rgb(57, 57, 57); } @@ -218,6 +226,14 @@ details > :not(:first-child) { color: blue; } + .console-message { + color: blue; + } + + .console-warning { + color: darkorange; + } + .console-input { background-color: rgb(229, 229, 229); } diff --git a/Userland/Libraries/LibWebView/InspectorClient.cpp b/Userland/Libraries/LibWebView/InspectorClient.cpp index d4f824baa4..4182240769 100644 --- a/Userland/Libraries/LibWebView/InspectorClient.cpp +++ b/Userland/Libraries/LibWebView/InspectorClient.cpp @@ -249,7 +249,10 @@ void InspectorClient::context_menu_screenshot_dom_node() { VERIFY(m_context_menu_data.has_value()); - m_content_web_view.take_dom_node_screenshot(m_context_menu_data->dom_node_id).release_value_but_fixme_should_propagate_errors(); + if (auto result = m_content_web_view.take_dom_node_screenshot(m_context_menu_data->dom_node_id); result.is_error()) + append_console_warning(MUST(String::formatted("Warning: {}", result.error()))); + else + append_console_message(MUST(String::formatted("Screenshot saved to: {}", result.value()))); m_context_menu_data.clear(); } @@ -645,13 +648,30 @@ void InspectorClient::handle_console_messages(i32 start_index, ReadonlySpan> "sv); builder.append(MUST(JS::MarkupGenerator::html_from_source(source))); append_console_output(builder.string_view()); } +void InspectorClient::append_console_message(StringView message) +{ + StringBuilder builder; + builder.append(""sv); + builder.appendff("{}", message); + + append_console_output(builder.string_view()); +} + +void InspectorClient::append_console_warning(StringView warning) +{ + StringBuilder builder; + builder.append(""sv); + builder.appendff("{}", warning); + + append_console_output(builder.string_view()); +} + void InspectorClient::append_console_output(StringView html) { auto html_base64 = MUST(encode_base64(html.bytes())); diff --git a/Userland/Libraries/LibWebView/InspectorClient.h b/Userland/Libraries/LibWebView/InspectorClient.h index 96cfb2b85a..8dc4192d2e 100644 --- a/Userland/Libraries/LibWebView/InspectorClient.h +++ b/Userland/Libraries/LibWebView/InspectorClient.h @@ -53,6 +53,8 @@ private: void handle_console_messages(i32 start_index, ReadonlySpan message_types, ReadonlySpan messages); void append_console_source(StringView); + void append_console_message(StringView); + void append_console_warning(StringView); void append_console_output(StringView); void clear_console_output(); diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp index b0b0469437..48fc0c21ff 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.cpp +++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp @@ -5,7 +5,6 @@ */ #include -#include #include #include #include @@ -394,7 +393,7 @@ void ViewImplementation::handle_web_content_process_crash() load_html(builder.to_deprecated_string()); } -static ErrorOr save_screenshot(Gfx::ShareableBitmap const& bitmap) +static ErrorOr save_screenshot(Gfx::ShareableBitmap const& bitmap) { if (!bitmap.is_valid()) return Error::from_string_view("Failed to take a screenshot"sv); @@ -407,10 +406,10 @@ static ErrorOr save_screenshot(Gfx::ShareableBitmap const& bitmap) auto screenshot_file = TRY(Core::File::open(path.string(), Core::File::OpenMode::Write)); TRY(screenshot_file->write_until_depleted(encoded)); - return {}; + return path; } -ErrorOr ViewImplementation::take_screenshot(ScreenshotType type) +ErrorOr ViewImplementation::take_screenshot(ScreenshotType type) { Gfx::ShareableBitmap bitmap; @@ -424,16 +423,13 @@ ErrorOr ViewImplementation::take_screenshot(ScreenshotType type) break; } - TRY(save_screenshot(bitmap)); - return {}; + return save_screenshot(bitmap); } -ErrorOr ViewImplementation::take_dom_node_screenshot(i32 node_id) +ErrorOr ViewImplementation::take_dom_node_screenshot(i32 node_id) { auto bitmap = client().take_dom_node_screenshot(node_id); - TRY(save_screenshot(bitmap)); - - return {}; + return save_screenshot(bitmap); } void ViewImplementation::set_user_style_sheet(String source) diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index 82b995cb41..cb07b5e937 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -95,8 +96,8 @@ public: Visible, Full, }; - ErrorOr take_screenshot(ScreenshotType); - ErrorOr take_dom_node_screenshot(i32); + ErrorOr take_screenshot(ScreenshotType); + ErrorOr take_dom_node_screenshot(i32); void set_user_style_sheet(String source); // Load Native.css as the User style sheet, which attempts to make WebView content look as close to