mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
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.
This commit is contained in:
parent
ce8c34a8c9
commit
b572a91a6f
6 changed files with 455 additions and 0 deletions
|
@ -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>() };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue