mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:07:34 +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
|
@ -598,6 +598,14 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
|
||||||
return active_tab().view().get_element_property(element_id, name);
|
return active_tab().view().get_element_property(element_id, name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
new_tab.on_get_active_documents_type = [this]() {
|
||||||
|
return active_tab().view().get_active_documents_type();
|
||||||
|
};
|
||||||
|
|
||||||
|
new_tab.on_get_computed_value_for_element = [this](i32 element_id, String const& property_name) {
|
||||||
|
return active_tab().view().get_computed_value_for_element(element_id, property_name);
|
||||||
|
};
|
||||||
|
|
||||||
new_tab.load(url);
|
new_tab.load(url);
|
||||||
|
|
||||||
dbgln_if(SPAM_DEBUG, "Added new tab {:p}, loading {}", &new_tab, url);
|
dbgln_if(SPAM_DEBUG, "Added new tab {:p}, loading {}", &new_tab, url);
|
||||||
|
|
|
@ -72,6 +72,8 @@ public:
|
||||||
Function<Optional<Vector<i32>>(i32 start_node_id, String const&)> on_query_selector_all;
|
Function<Optional<Vector<i32>>(i32 start_node_id, String const&)> on_query_selector_all;
|
||||||
Function<Optional<String>(i32 element_id, String const&)> on_get_element_attribute;
|
Function<Optional<String>(i32 element_id, String const&)> on_get_element_attribute;
|
||||||
Function<Optional<String>(i32 element_id, String const&)> on_get_element_property;
|
Function<Optional<String>(i32 element_id, String const&)> on_get_element_property;
|
||||||
|
Function<String()> on_get_active_documents_type;
|
||||||
|
Function<String(i32 element_id, String const&)> on_get_computed_value_for_element;
|
||||||
|
|
||||||
enum class InspectorTarget {
|
enum class InspectorTarget {
|
||||||
Document,
|
Document,
|
||||||
|
|
|
@ -535,6 +535,16 @@ Optional<String> OutOfProcessWebView::get_element_property(i32 element_id, Strin
|
||||||
return client().get_element_property(element_id, name);
|
return client().get_element_property(element_id, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String OutOfProcessWebView::get_active_documents_type()
|
||||||
|
{
|
||||||
|
return client().get_active_documents_type();
|
||||||
|
}
|
||||||
|
|
||||||
|
String OutOfProcessWebView::get_computed_value_for_element(i32 element_id, String const& property_name)
|
||||||
|
{
|
||||||
|
return client().get_computed_value_for_element(element_id, property_name);
|
||||||
|
}
|
||||||
|
|
||||||
void OutOfProcessWebView::set_content_filters(Vector<String> filters)
|
void OutOfProcessWebView::set_content_filters(Vector<String> filters)
|
||||||
{
|
{
|
||||||
client().async_set_content_filters(filters);
|
client().async_set_content_filters(filters);
|
||||||
|
|
|
@ -62,6 +62,8 @@ public:
|
||||||
Optional<Vector<i32>> query_selector_all(i32 start_node_id, String const& selector);
|
Optional<Vector<i32>> query_selector_all(i32 start_node_id, String const& selector);
|
||||||
Optional<String> get_element_attribute(i32 element_id, String const& name);
|
Optional<String> get_element_attribute(i32 element_id, String const& name);
|
||||||
Optional<String> get_element_property(i32 element_id, String const& name);
|
Optional<String> 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);
|
||||||
|
|
||||||
void set_content_filters(Vector<String>);
|
void set_content_filters(Vector<String>);
|
||||||
void set_proxy_mappings(Vector<String> proxies, HashMap<String, size_t> mappings);
|
void set_proxy_mappings(Vector<String> proxies, HashMap<String, size_t> mappings);
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <LibJS/Parser.h>
|
#include <LibJS/Parser.h>
|
||||||
#include <LibJS/Runtime/ConsoleObject.h>
|
#include <LibJS/Runtime/ConsoleObject.h>
|
||||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||||
|
#include <LibWeb/CSS/PropertyID.h>
|
||||||
#include <LibWeb/Cookie/ParsedCookie.h>
|
#include <LibWeb/Cookie/ParsedCookie.h>
|
||||||
#include <LibWeb/DOM/Document.h>
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/DOM/NodeList.h>
|
#include <LibWeb/DOM/NodeList.h>
|
||||||
|
@ -517,6 +518,49 @@ Messages::WebContentServer::GetElementPropertyResponse ConnectionFromClient::get
|
||||||
return { string_or_error.release_value() };
|
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()
|
Messages::WebContentServer::GetSelectedTextResponse ConnectionFromClient::get_selected_text()
|
||||||
{
|
{
|
||||||
return page().focused_context().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::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::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::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::GetLocalStorageEntriesResponse get_local_storage_entries() override;
|
||||||
virtual Messages::WebContentServer::GetSessionStorageEntriesResponse get_session_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)
|
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_attribute(i32 element_id, String name) => (Optional<String> attribute)
|
||||||
get_element_property(i32 element_id, String name) => (Optional<String> property)
|
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) =|
|
run_javascript(String js_source) =|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue