From 12b3332d3c898ae5cc6cab160d5d2b4c67f211ab Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 9 Apr 2024 18:25:46 -0400 Subject: [PATCH] WebContent: Use outerHTML to copy a DOM node's HTML in the Inspector We can use outerHTML now instead of cloning the node into a temporary container and invoking the container's innerHTML. --- .../Services/WebContent/ConnectionFromClient.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index 31545af8fb2..1f0a4ecb74b 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -745,11 +745,18 @@ void ConnectionFromClient::get_dom_node_html(u64 page_id, i32 node_id) if (!dom_node) return; - // FIXME: Implement Element's outerHTML attribute. - auto container = Web::DOM::create_element(dom_node->document(), Web::HTML::TagNames::div, Web::Namespace::HTML).release_value_but_fixme_should_propagate_errors(); - container->append_child(dom_node->clone_node(nullptr, true)).release_value_but_fixme_should_propagate_errors(); + String html; + + if (dom_node->is_element()) { + auto const& element = static_cast(*dom_node); + html = element.outer_html().release_value_but_fixme_should_propagate_errors(); + } else if (dom_node->is_text() || dom_node->is_comment()) { + auto const& character_data = static_cast(*dom_node); + html = character_data.data(); + } else { + return; + } - auto html = container->inner_html().release_value_but_fixme_should_propagate_errors(); async_did_get_dom_node_html(page_id, move(html)); }