+
+
)~~~"sv);
auto generate_property_table = [&](auto name) {
@@ -384,4 +419,100 @@ String InspectorClient::generate_accessibility_tree(JsonObject const& accessibil
return MUST(builder.to_string());
}
+void InspectorClient::request_console_messages()
+{
+ VERIFY(!m_waiting_for_messages);
+
+ m_content_web_view.js_console_request_messages(m_highest_received_message_index + 1);
+ m_waiting_for_messages = true;
+}
+
+void InspectorClient::handle_console_message(i32 message_index)
+{
+ if (message_index <= m_highest_received_message_index) {
+ dbgln("Notified about console message we already have");
+ return;
+ }
+ if (message_index <= m_highest_notified_message_index) {
+ dbgln("Notified about console message we're already aware of");
+ return;
+ }
+
+ m_highest_notified_message_index = message_index;
+
+ if (!m_waiting_for_messages)
+ request_console_messages();
+}
+
+void InspectorClient::handle_console_messages(i32 start_index, ReadonlySpan
message_types, ReadonlySpan messages)
+{
+ auto end_index = start_index + static_cast(message_types.size()) - 1;
+ if (end_index <= m_highest_received_message_index) {
+ dbgln("Received old console messages");
+ return;
+ }
+
+ for (size_t i = 0; i < message_types.size(); ++i) {
+ auto const& type = message_types[i];
+ auto const& message = messages[i];
+
+ if (type == "html"sv)
+ append_console_output(message);
+ else if (type == "clear"sv)
+ clear_console_output();
+ else if (type == "group"sv)
+ begin_console_group(message, true);
+ else if (type == "groupCollapsed"sv)
+ begin_console_group(message, false);
+ else if (type == "groupEnd"sv)
+ end_console_group();
+ else
+ VERIFY_NOT_REACHED();
+ }
+
+ m_highest_received_message_index = end_index;
+ m_waiting_for_messages = false;
+
+ if (m_highest_received_message_index < m_highest_notified_message_index)
+ request_console_messages();
+}
+
+void InspectorClient::append_console_source(StringView source)
+{
+ StringBuilder builder;
+
+ builder.append("> "sv);
+ builder.append(MUST(JS::MarkupGenerator::html_from_source(source)));
+
+ append_console_output(builder.string_view());
+}
+
+void InspectorClient::append_console_output(StringView html)
+{
+ auto html_base64 = MUST(encode_base64(html.bytes()));
+
+ auto script = MUST(String::formatted("inspector.appendConsoleOutput(\"{}\");", html_base64));
+ m_inspector_web_view.run_javascript(script);
+}
+
+void InspectorClient::clear_console_output()
+{
+ static constexpr auto script = "inspector.clearConsoleOutput();"sv;
+ m_inspector_web_view.run_javascript(script);
+}
+
+void InspectorClient::begin_console_group(StringView label, bool start_expanded)
+{
+ auto label_base64 = MUST(encode_base64(label.bytes()));
+
+ auto script = MUST(String::formatted("inspector.beginConsoleGroup(\"{}\", {});", label_base64, start_expanded));
+ m_inspector_web_view.run_javascript(script);
+}
+
+void InspectorClient::end_console_group()
+{
+ static constexpr auto script = "inspector.endConsoleGroup();"sv;
+ m_inspector_web_view.run_javascript(script);
+}
+
}
diff --git a/Userland/Libraries/LibWebView/InspectorClient.h b/Userland/Libraries/LibWebView/InspectorClient.h
index 042048d2ac..a2fa997bfd 100644
--- a/Userland/Libraries/LibWebView/InspectorClient.h
+++ b/Userland/Libraries/LibWebView/InspectorClient.h
@@ -26,11 +26,22 @@ public:
private:
void load_inspector();
+
String generate_dom_tree(JsonObject const&);
String generate_accessibility_tree(JsonObject const&);
-
void select_node(i32 node_id);
+ void request_console_messages();
+ void handle_console_message(i32 message_index);
+ void handle_console_messages(i32 start_index, ReadonlySpan message_types, ReadonlySpan messages);
+
+ void append_console_source(StringView);
+ void append_console_output(StringView);
+ void clear_console_output();
+
+ void begin_console_group(StringView label, bool start_expanded);
+ void end_console_group();
+
ViewImplementation& m_content_web_view;
ViewImplementation& m_inspector_web_view;
@@ -38,6 +49,10 @@ private:
Optional m_pending_selection;
bool m_dom_tree_loaded { false };
+
+ i32 m_highest_notified_message_index { -1 };
+ i32 m_highest_received_message_index { -1 };
+ bool m_waiting_for_messages { false };
};
}