mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 04:27:45 +00:00
WebContent+Friends: Add IPC and plumbing for WebDriver endpoint
To use the `GET /session/{id}/element/{id}/css/{property name}` WebDriver endpoint, two new IPC calls through the Browser are implemented: - get_active_documents_type returns the type of the active document, which is either "xml" or "html" - get_computed_value_for_element returns the computed CSS value (as String) for the given element and CSS property name
This commit is contained in:
parent
eda566d112
commit
202b2be1f2
7 changed files with 70 additions and 0 deletions
|
@ -18,6 +18,7 @@
|
|||
#include <LibJS/Parser.h>
|
||||
#include <LibJS/Runtime/ConsoleObject.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/Cookie/ParsedCookie.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/DOM/NodeList.h>
|
||||
|
@ -517,6 +518,49 @@ Messages::WebContentServer::GetElementPropertyResponse ConnectionFromClient::get
|
|||
return { string_or_error.release_value() };
|
||||
}
|
||||
|
||||
Messages::WebContentServer::GetActiveDocumentsTypeResponse ConnectionFromClient::get_active_documents_type()
|
||||
{
|
||||
auto* active_document = page().top_level_browsing_context().active_document();
|
||||
|
||||
if (!active_document)
|
||||
return { "" };
|
||||
|
||||
auto type = active_document->document_type();
|
||||
|
||||
switch (type) {
|
||||
case Web::DOM::Document::Type::HTML:
|
||||
return { "html" };
|
||||
break;
|
||||
case Web::DOM::Document::Type::XML:
|
||||
return { "xml" };
|
||||
break;
|
||||
}
|
||||
|
||||
return { "" };
|
||||
}
|
||||
|
||||
Messages::WebContentServer::GetComputedValueForElementResponse ConnectionFromClient::get_computed_value_for_element(i32 element_id, String const& property_name)
|
||||
{
|
||||
auto* node = Web::DOM::Node::from_id(element_id);
|
||||
if (!node)
|
||||
return { "" };
|
||||
|
||||
if (!node->is_element())
|
||||
return { "" };
|
||||
|
||||
auto& element = verify_cast<Web::DOM::Element>(*node);
|
||||
|
||||
auto property_id = Web::CSS::property_id_from_string(property_name);
|
||||
|
||||
auto computed_values = element.computed_css_values();
|
||||
if (!computed_values)
|
||||
return { "" };
|
||||
|
||||
auto style_value = computed_values->property(property_id);
|
||||
|
||||
return { style_value->to_string() };
|
||||
}
|
||||
|
||||
Messages::WebContentServer::GetSelectedTextResponse ConnectionFromClient::get_selected_text()
|
||||
{
|
||||
return page().focused_context().selected_text();
|
||||
|
|
|
@ -83,6 +83,8 @@ private:
|
|||
virtual Messages::WebContentServer::QuerySelectorAllResponse query_selector_all(i32 start_node_id, String const& selector) override;
|
||||
virtual Messages::WebContentServer::GetElementAttributeResponse get_element_attribute(i32 element_id, String const& name) override;
|
||||
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::GetLocalStorageEntriesResponse get_local_storage_entries() override;
|
||||
virtual Messages::WebContentServer::GetSessionStorageEntriesResponse get_session_storage_entries() override;
|
||||
|
|
|
@ -41,6 +41,8 @@ endpoint WebContentServer
|
|||
query_selector_all(i32 start_node_id, String selector) => (Optional<Vector<i32>> elements_ids)
|
||||
get_element_attribute(i32 element_id, String name) => (Optional<String> attribute)
|
||||
get_element_property(i32 element_id, String name) => (Optional<String> property)
|
||||
get_active_documents_type() => (String type)
|
||||
get_computed_value_for_element(i32 element_id, String property_name) => (String computed_value)
|
||||
|
||||
run_javascript(String js_source) =|
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue