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

LibWeb+WebDriver: Support running headless WebDriver sessions

This adds an "extension capability" for clients to indicate that a
headless browser should be used for the session.
This commit is contained in:
Timothy Flynn 2022-11-22 07:38:07 -05:00 committed by Linus Groh
parent e840d27d8e
commit 7edd57dc87
6 changed files with 76 additions and 15 deletions

View file

@ -17,8 +17,9 @@
namespace WebDriver {
Session::Session(unsigned session_id, NonnullRefPtr<Client> client)
Session::Session(unsigned session_id, NonnullRefPtr<Client> client, Web::WebDriver::LadybirdOptions options)
: m_client(move(client))
, m_options(move(options))
, m_id(session_id)
{
}
@ -63,14 +64,26 @@ ErrorOr<void> Session::start()
auto web_content_socket_path = String::formatted("/tmp/webdriver/session_{}_{}", getpid(), m_id);
auto web_content_server = TRY(create_server(web_content_socket_path, promise));
char const* argv[] = {
"/bin/Browser",
"--webdriver-content-path",
web_content_socket_path.characters(),
nullptr,
};
if (m_options.headless) {
char const* argv[] = {
"/bin/headless-browser",
"--webdriver-ipc-path",
web_content_socket_path.characters(),
"about:blank",
nullptr,
};
m_browser_pid = TRY(Core::System::posix_spawn("/bin/Browser"sv, nullptr, nullptr, const_cast<char**>(argv), environ));
m_browser_pid = TRY(Core::System::posix_spawn("/bin/headless-browser"sv, nullptr, nullptr, const_cast<char**>(argv), environ));
} else {
char const* argv[] = {
"/bin/Browser",
"--webdriver-content-path",
web_content_socket_path.characters(),
nullptr,
};
m_browser_pid = TRY(Core::System::posix_spawn("/bin/Browser"sv, nullptr, nullptr, const_cast<char**>(argv), environ));
}
// FIXME: Allow this to be more asynchronous. For now, this at least allows us to propagate
// errors received while accepting the Browser and WebContent sockets.