mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +00:00
WebDriver+Friends: Add IPC and plumbing for Element-getting
This extends the IPC calls `get_document_element` and `query_selector_all` to be usable by the WebDriver. For this the `WebDriverConnection` provides the same interfaces and takes care of routing the data through the Browser.
This commit is contained in:
parent
281991057c
commit
5d762bd448
7 changed files with 49 additions and 0 deletions
|
@ -582,6 +582,14 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
|
||||||
return active_tab().view().get_session_storage_entries();
|
return active_tab().view().get_session_storage_entries();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
new_tab.on_get_document_element = [this]() {
|
||||||
|
return active_tab().view().get_document_element();
|
||||||
|
};
|
||||||
|
|
||||||
|
new_tab.on_query_selector_all = [this](i32 start_node_id, String const& selector) {
|
||||||
|
return active_tab().view().query_selector_all(start_node_id, selector);
|
||||||
|
};
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
@ -68,6 +68,8 @@ public:
|
||||||
Function<Vector<Web::Cookie::Cookie>()> on_get_cookies_entries;
|
Function<Vector<Web::Cookie::Cookie>()> on_get_cookies_entries;
|
||||||
Function<OrderedHashMap<String, String>()> on_get_local_storage_entries;
|
Function<OrderedHashMap<String, String>()> on_get_local_storage_entries;
|
||||||
Function<OrderedHashMap<String, String>()> on_get_session_storage_entries;
|
Function<OrderedHashMap<String, String>()> on_get_session_storage_entries;
|
||||||
|
Function<Optional<i32>()> on_get_document_element;
|
||||||
|
Function<Optional<Vector<i32>>(i32 start_node_id, String const&)> on_query_selector_all;
|
||||||
|
|
||||||
enum class InspectorTarget {
|
enum class InspectorTarget {
|
||||||
Document,
|
Document,
|
||||||
|
|
|
@ -121,4 +121,26 @@ void WebDriverConnection::update_cookie(Web::Cookie::Cookie const& cookie)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Messages::WebDriverSessionClient::GetDocumentElementResponse WebDriverConnection::get_document_element()
|
||||||
|
{
|
||||||
|
dbgln("WebDriverConnection: get_document_element");
|
||||||
|
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||||
|
auto& tab = browser_window->active_tab();
|
||||||
|
if (tab.on_get_document_element)
|
||||||
|
return { tab.on_get_document_element() };
|
||||||
|
}
|
||||||
|
return { {} };
|
||||||
|
}
|
||||||
|
|
||||||
|
Messages::WebDriverSessionClient::QuerySelectorAllResponse WebDriverConnection::query_selector_all(i32 start_node_id, String const& selector)
|
||||||
|
{
|
||||||
|
dbgln("WebDriverConnection: query_selector_all");
|
||||||
|
if (auto browser_window = m_browser_window.strong_ref()) {
|
||||||
|
auto& tab = browser_window->active_tab();
|
||||||
|
if (tab.on_query_selector_all)
|
||||||
|
return { tab.on_query_selector_all(start_node_id, selector) };
|
||||||
|
}
|
||||||
|
return { {} };
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,8 @@ public:
|
||||||
virtual Messages::WebDriverSessionClient::GetNamedCookieResponse get_named_cookie(String const& name) override;
|
virtual Messages::WebDriverSessionClient::GetNamedCookieResponse get_named_cookie(String const& name) override;
|
||||||
virtual void add_cookie(Web::Cookie::ParsedCookie const&) override;
|
virtual void add_cookie(Web::Cookie::ParsedCookie const&) override;
|
||||||
virtual void update_cookie(Web::Cookie::Cookie const&) override;
|
virtual void update_cookie(Web::Cookie::Cookie const&) override;
|
||||||
|
virtual Messages::WebDriverSessionClient::GetDocumentElementResponse get_document_element() override;
|
||||||
|
virtual Messages::WebDriverSessionClient::QuerySelectorAllResponse query_selector_all(i32 start_node_id, String const& selector) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window);
|
WebDriverConnection(NonnullOwnPtr<Core::Stream::LocalSocket> socket, NonnullRefPtr<BrowserWindow> browser_window);
|
||||||
|
|
|
@ -16,5 +16,7 @@ endpoint WebDriverSessionClient {
|
||||||
get_named_cookie(String name) => (Optional<Web::Cookie::Cookie> cookie)
|
get_named_cookie(String name) => (Optional<Web::Cookie::Cookie> cookie)
|
||||||
add_cookie(Web::Cookie::ParsedCookie cookie) =|
|
add_cookie(Web::Cookie::ParsedCookie cookie) =|
|
||||||
update_cookie(Web::Cookie::Cookie cookie) =|
|
update_cookie(Web::Cookie::Cookie cookie) =|
|
||||||
|
get_document_element() => (Optional<i32> document_element_id)
|
||||||
|
query_selector_all(i32 start_node_id, String selector) => (Optional<Vector<i32>> elements_ids)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -515,6 +515,16 @@ OrderedHashMap<String, String> OutOfProcessWebView::get_session_storage_entries(
|
||||||
return client().get_session_storage_entries();
|
return client().get_session_storage_entries();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<i32> OutOfProcessWebView::get_document_element()
|
||||||
|
{
|
||||||
|
return client().get_document_element();
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<Vector<i32>> OutOfProcessWebView::query_selector_all(i32 start_node_id, String const& selector)
|
||||||
|
{
|
||||||
|
return client().query_selector_all(start_node_id, selector);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
@ -58,6 +58,9 @@ public:
|
||||||
OrderedHashMap<String, String> get_local_storage_entries();
|
OrderedHashMap<String, String> get_local_storage_entries();
|
||||||
OrderedHashMap<String, String> get_session_storage_entries();
|
OrderedHashMap<String, String> get_session_storage_entries();
|
||||||
|
|
||||||
|
Optional<i32> get_document_element();
|
||||||
|
Optional<Vector<i32>> query_selector_all(i32 start_node_id, String const& selector);
|
||||||
|
|
||||||
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);
|
||||||
void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
|
void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue