diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp index 79ae17edd3..b8ad8d549e 100644 --- a/Userland/Applications/Browser/BrowserWindow.cpp +++ b/Userland/Applications/Browser/BrowserWindow.cpp @@ -607,6 +607,10 @@ void BrowserWindow::create_new_tab(URL url, bool activate) return active_tab().view().get_computed_value_for_element(element_id, property_name); }; + new_tab.webdriver_endpoints().on_get_element_text = [this](i32 element_id) { + return active_tab().view().get_element_text(element_id); + }; + new_tab.webdriver_endpoints().on_get_element_tag_name = [this](i32 element_id) { return active_tab().view().get_element_tag_name(element_id); }; diff --git a/Userland/Applications/Browser/WebDriverEndpoints.h b/Userland/Applications/Browser/WebDriverEndpoints.h index 732304fb0e..c4f522c64f 100644 --- a/Userland/Applications/Browser/WebDriverEndpoints.h +++ b/Userland/Applications/Browser/WebDriverEndpoints.h @@ -23,6 +23,7 @@ public: Function(i32 element_id, String const&)> on_get_element_property; Function on_get_active_documents_type; Function on_get_computed_value_for_element; + Function on_get_element_text; Function on_get_element_tag_name; }; diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index dd745842cd..3c8c955d67 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -545,6 +545,11 @@ String OutOfProcessWebView::get_computed_value_for_element(i32 element_id, Strin return client().get_computed_value_for_element(element_id, property_name); } +String OutOfProcessWebView::get_element_text(i32 element_id) +{ + return client().get_element_text(element_id); +} + String OutOfProcessWebView::get_element_tag_name(i32 element_id) { return client().get_element_tag_name(element_id); diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index 617f1bf1b4..423bd62728 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -64,6 +64,7 @@ public: Optional get_element_property(i32 element_id, String const& name); String get_active_documents_type(); String get_computed_value_for_element(i32 element_id, String const& property_name); + String get_element_text(i32 element_id); String get_element_tag_name(i32 element_id); void set_content_filters(Vector); diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index a3c4cf811c..92512b0b26 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -561,6 +561,20 @@ Messages::WebContentServer::GetComputedValueForElementResponse ConnectionFromCli return { style_value->to_string() }; } +Messages::WebContentServer::GetElementTextResponse ConnectionFromClient::get_element_text(i32 element_id) +{ + auto* node = Web::DOM::Node::from_id(element_id); + if (!node) + return { "" }; + + if (!node->is_element()) + return { "" }; + + auto& element = verify_cast(*node); + + return { element.layout_node()->dom_node()->text_content() }; +} + Messages::WebContentServer::GetElementTagNameResponse ConnectionFromClient::get_element_tag_name(i32 element_id) { auto* node = Web::DOM::Node::from_id(element_id); diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h index 13ae9f6dbe..4916ee8460 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.h +++ b/Userland/Services/WebContent/ConnectionFromClient.h @@ -85,6 +85,7 @@ private: virtual Messages::WebContentServer::GetElementPropertyResponse get_element_property(i32 element_id, String const& name) override; virtual Messages::WebContentServer::GetActiveDocumentsTypeResponse get_active_documents_type() override; virtual Messages::WebContentServer::GetComputedValueForElementResponse get_computed_value_for_element(i32 element_id, String const& property_name) override; + virtual Messages::WebContentServer::GetElementTextResponse get_element_text(i32 element_id) override; virtual Messages::WebContentServer::GetElementTagNameResponse get_element_tag_name(i32 element_id) override; virtual Messages::WebContentServer::GetLocalStorageEntriesResponse get_local_storage_entries() override; diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index b22ff042db..125be1ba68 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -43,6 +43,7 @@ endpoint WebContentServer get_element_property(i32 element_id, String name) => (Optional property) get_active_documents_type() => (String type) get_computed_value_for_element(i32 element_id, String property_name) => (String computed_value) + get_element_text(i32 element_id) => (String text) get_element_tag_name(i32 element_id) => (String tag_name) run_javascript(String js_source) =|