1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:37:46 +00:00

WebDriver: Specify callbacks for clients to launch browser windows

This moves the actual launching of browser windows to the WebDriver main
file. This will allow Ladybird to specify its own callback and re-use
Serenity's Session class.
This commit is contained in:
Timothy Flynn 2022-12-15 08:46:01 -05:00 committed by Linus Groh
parent 366f24a73b
commit 956fa84f12
5 changed files with 52 additions and 29 deletions

View file

@ -13,6 +13,31 @@
#include <LibMain/Main.h>
#include <WebDriver/Client.h>
static ErrorOr<pid_t> launch_browser(DeprecatedString const& socket_path)
{
char const* argv[] = {
"/bin/Browser",
"--webdriver-content-path",
socket_path.characters(),
nullptr,
};
return Core::System::posix_spawn("/bin/Browser"sv, nullptr, nullptr, const_cast<char**>(argv), environ);
}
static ErrorOr<pid_t> launch_headless_browser(DeprecatedString const& socket_path)
{
char const* argv[] = {
"/bin/headless-browser",
"--webdriver-ipc-path",
socket_path.characters(),
"about:blank",
nullptr,
};
return Core::System::posix_spawn("/bin/headless-browser"sv, nullptr, nullptr, const_cast<char**>(argv), environ);
}
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
DeprecatedString default_listen_address = "0.0.0.0";
@ -62,7 +87,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return;
}
auto maybe_client = WebDriver::Client::try_create(maybe_buffered_socket.release_value(), server);
auto maybe_client = WebDriver::Client::try_create(maybe_buffered_socket.release_value(), { launch_browser, launch_headless_browser }, server);
if (maybe_client.is_error()) {
warnln("Could not create a WebDriver client: {}", maybe_client.error());
return;