From ad1ba30b27ff2802b6e743c6b8970e4bd1309dfc Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 6 Nov 2024 18:45:04 -0500 Subject: [PATCH] WebContent: Serialize the document element's outer HTML for WebDriver --- .../Services/WebContent/WebDriverConnection.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index d53f31927bd..9094f153b18 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -2032,19 +2032,22 @@ Web::WebDriver::Response WebDriverConnection::element_send_keys_impl(String cons // 13.1 Get Page Source, https://w3c.github.io/webdriver/#dfn-get-page-source Messages::WebDriverClient::GetSourceResponse WebDriverConnection::get_source() { - // 1. If the current browsing context is no longer open, return error with error code no such window. + // 1. If session's current browsing context is no longer open, return error with error code no such window. TRY(ensure_current_browsing_context_is_open()); - // 2. Handle any user prompts and return its value if it is an error. + // 2. Try to handle any user prompts with session. handle_any_user_prompts([this]() { auto* document = current_browsing_context().active_document(); Optional source; - // 3. Let source be the result of invoking the fragment serializing algorithm on a fictional node whose only child is the document element providing true for the require well-formed flag. If this causes an exception to be thrown, let source be null. - if (auto result = document->serialize_fragment(Web::DOMParsing::RequireWellFormed::Yes); !result.is_error()) + // 3. Let source be the result of invoking the fragment serializing algorithm on a fictional node whose only + // child is the document element providing true for the require well-formed flag. If this causes an exception + // to be thrown, let source be null. + if (auto result = document->document_element()->serialize_fragment(Web::DOMParsing::RequireWellFormed::Yes, Web::DOM::FragmentSerializationMode::Outer); !result.is_error()) source = result.release_value(); - // 4. Let source be the result of serializing to string the current browsing context active document, if source is null. + // 4. Let source be the result of serializing to string session's current browsing context's active document, + // if source is null. if (!source.has_value()) source = MUST(document->serialize_fragment(Web::DOMParsing::RequireWellFormed::No));