summaryrefslogtreecommitdiff
path: root/Userland/Services/WebContent
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-11-02 18:02:19 +0000
committerLinus Groh <mail@linusgroh.de>2022-11-02 23:46:30 +0000
commitb572a91a6f2b71e9d60ff1e2884d1462b5a3e318 (patch)
treedbde1c4b76faf7e1ad2f1a31ec156d02f668a4fd /Userland/Services/WebContent
parentce8c34a8c9abf7845a2cc0017da7c89e5d2ac946 (diff)
downloadserenity-b572a91a6f2b71e9d60ff1e2884d1462b5a3e318.zip
LibWeb+WebContent: Add WebDriver infrastructure for executing scripts
This cannot be done on the Browser or WebDriver ends, or via the existing run_javascript() IPC endpoint, as we cannot transfer JS objects through the IPC boundary (yet), only serialized JSON, so the individual WebDriver steps around script execution need to run in the WebContent process.
Diffstat (limited to 'Userland/Services/WebContent')
-rw-r--r--Userland/Services/WebContent/ConnectionFromClient.cpp21
-rw-r--r--Userland/Services/WebContent/ConnectionFromClient.h2
-rw-r--r--Userland/Services/WebContent/WebContentServer.ipc3
3 files changed, 26 insertions, 0 deletions
diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp
index 71c632c05a..c48681b9f5 100644
--- a/Userland/Services/WebContent/ConnectionFromClient.cpp
+++ b/Userland/Services/WebContent/ConnectionFromClient.cpp
@@ -17,6 +17,7 @@
#include <LibJS/Heap/Heap.h>
#include <LibJS/Parser.h>
#include <LibJS/Runtime/ConsoleObject.h>
+#include <LibJS/Runtime/JSONObject.h>
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/Cookie/ParsedCookie.h>
@@ -705,4 +706,24 @@ void ConnectionFromClient::set_system_visibility_state(bool visible)
: Web::HTML::VisibilityState::Hidden);
}
+Messages::WebContentServer::WebdriverExecuteScriptResponse ConnectionFromClient::webdriver_execute_script(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async)
+{
+ auto& page = m_page_host->page();
+
+ auto* window = page.top_level_browsing_context().active_window();
+ auto& vm = window->vm();
+
+ auto arguments = JS::MarkedVector<JS::Value> { vm.heap() };
+ for (auto const& argument_string : json_arguments) {
+ // NOTE: These are assumed to be valid JSON values.
+ auto json_value = MUST(JsonValue::from_string(argument_string));
+ arguments.append(JS::JSONObject::parse_json_value(vm, json_value));
+ }
+
+ auto result = async
+ ? Web::WebDriver::execute_async_script(page, body, move(arguments), timeout)
+ : Web::WebDriver::execute_script(page, body, move(arguments), timeout);
+ return { result.type, result.value.serialized<StringBuilder>() };
+}
+
}
diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h
index bdbcf85b73..c27294e840 100644
--- a/Userland/Services/WebContent/ConnectionFromClient.h
+++ b/Userland/Services/WebContent/ConnectionFromClient.h
@@ -96,6 +96,8 @@ private:
virtual Messages::WebContentServer::GetSelectedTextResponse get_selected_text() override;
virtual void select_all() override;
+ virtual Messages::WebContentServer::WebdriverExecuteScriptResponse webdriver_execute_script(String const& body, Vector<String> const& json_arguments, Optional<u64> const& timeout, bool async) override;
+
void flush_pending_paint_requests();
NonnullOwnPtr<PageHost> m_page_host;
diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc
index 9302fd27be..cbd1830e4d 100644
--- a/Userland/Services/WebContent/WebContentServer.ipc
+++ b/Userland/Services/WebContent/WebContentServer.ipc
@@ -4,6 +4,7 @@
#include <LibGfx/ShareableBitmap.h>
#include <LibWeb/CSS/PreferredColorScheme.h>
#include <LibWeb/CSS/Selector.h>
+#include <LibWeb/WebDriver/ExecuteScript.h>
endpoint WebContentServer
{
@@ -46,6 +47,8 @@ endpoint WebContentServer
get_element_text(i32 element_id) => (String text)
get_element_tag_name(i32 element_id) => (String tag_name)
+ webdriver_execute_script(String body, Vector<String> json_arguments, Optional<u64> timeout, bool async) => (Web::WebDriver::ExecuteScriptResultType result_type, String json_result)
+
run_javascript(String js_source) =|
dump_layout_tree() => (String dump)