mirror of
https://github.com/RGBCube/serenity
synced 2025-07-19 18:57:40 +00:00
Ladybird/WebDriver: Support running headless WebDriver sessions
This adds a dependency from WebDriver to Lagom's headless-browser to be used if the client's required capabilities indicate to do so.
This commit is contained in:
parent
69cd0d6599
commit
a1e380cc38
5 changed files with 46 additions and 11 deletions
|
@ -29,6 +29,7 @@
|
||||||
#include <QSocketNotifier>
|
#include <QSocketNotifier>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <WebContent/ConnectionFromClient.h>
|
#include <WebContent/ConnectionFromClient.h>
|
||||||
|
#include <WebContent/PageHost.h>
|
||||||
#include <WebContent/WebDriverConnection.h>
|
#include <WebContent/WebDriverConnection.h>
|
||||||
|
|
||||||
static ErrorOr<void> load_content_filters();
|
static ErrorOr<void> load_content_filters();
|
||||||
|
@ -103,7 +104,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
QSocketNotifier webdriver_notifier(QSocketNotifier::Type::Read);
|
QSocketNotifier webdriver_notifier(QSocketNotifier::Type::Read);
|
||||||
RefPtr<WebContent::WebDriverConnection> webdriver_client;
|
RefPtr<WebContent::WebDriverConnection> webdriver_client;
|
||||||
if (webdriver_fd_passing_socket >= 0)
|
if (webdriver_fd_passing_socket >= 0)
|
||||||
webdriver_client = TRY(create_connection_from_passed_socket<WebContent::WebDriverConnection>(webdriver_fd_passing_socket, "WebDriver"sv, webdriver_notifier, *webcontent_client, webcontent_client->page_host()));
|
webdriver_client = TRY(create_connection_from_passed_socket<WebContent::WebDriverConnection>(webdriver_fd_passing_socket, "WebDriver"sv, webdriver_notifier, webcontent_client->page_host()));
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ set(WEBDRIVER_SOURCE_DIR ${SERENITY_SOURCE_DIR}/Userland/Services/WebDriver)
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
${WEBDRIVER_SOURCE_DIR}/Client.cpp
|
${WEBDRIVER_SOURCE_DIR}/Client.cpp
|
||||||
${WEBDRIVER_SOURCE_DIR}/WebContentConnection.cpp
|
${WEBDRIVER_SOURCE_DIR}/WebContentConnection.cpp
|
||||||
|
../Utilities.cpp
|
||||||
Session.cpp
|
Session.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
)
|
)
|
||||||
|
@ -14,3 +15,4 @@ target_include_directories(WebDriver PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/..)
|
||||||
target_include_directories(WebDriver PRIVATE ${SERENITY_SOURCE_DIR}/Userland)
|
target_include_directories(WebDriver PRIVATE ${SERENITY_SOURCE_DIR}/Userland)
|
||||||
target_include_directories(WebDriver PRIVATE ${SERENITY_SOURCE_DIR}/Userland/Services)
|
target_include_directories(WebDriver PRIVATE ${SERENITY_SOURCE_DIR}/Userland/Services)
|
||||||
target_link_libraries(WebDriver PRIVATE Qt::Core Qt::Network LibCore LibGfx LibIPC LibJS LibMain LibWeb LibWebSocket)
|
target_link_libraries(WebDriver PRIVATE Qt::Core Qt::Network LibCore LibGfx LibIPC LibJS LibMain LibWeb LibWebSocket)
|
||||||
|
add_dependencies(WebDriver headless-browser)
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#define AK_DONT_REPLACE_STD
|
#define AK_DONT_REPLACE_STD
|
||||||
|
|
||||||
#include "Session.h"
|
#include "Session.h"
|
||||||
|
#include "../Utilities.h"
|
||||||
#include <LibCore/Stream.h>
|
#include <LibCore/Stream.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <WebDriver/Client.h>
|
#include <WebDriver/Client.h>
|
||||||
|
@ -18,8 +19,9 @@
|
||||||
|
|
||||||
namespace WebDriver {
|
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_client(move(client))
|
||||||
|
, m_options(move(options))
|
||||||
, m_id(session_id)
|
, m_id(session_id)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -51,6 +53,28 @@ ErrorOr<void> Session::start()
|
||||||
|
|
||||||
auto fd_passing_socket_string = String::number(webcontent_fd_passing_fd);
|
auto fd_passing_socket_string = String::number(webcontent_fd_passing_fd);
|
||||||
|
|
||||||
|
if (m_options.headless) {
|
||||||
|
auto resouces = String::formatted("{}/res", s_serenity_resource_root);
|
||||||
|
auto error_page = String::formatted("{}/res/html/error.html", s_serenity_resource_root);
|
||||||
|
auto certs = String::formatted("{}/etc/ca_certs.ini", s_serenity_resource_root);
|
||||||
|
|
||||||
|
char const* argv[] = {
|
||||||
|
"headless-browser",
|
||||||
|
"--resources",
|
||||||
|
resouces.characters(),
|
||||||
|
"--error-page",
|
||||||
|
error_page.characters(),
|
||||||
|
"--certs",
|
||||||
|
certs.characters(),
|
||||||
|
"--webdriver-fd-passing-socket",
|
||||||
|
fd_passing_socket_string.characters(),
|
||||||
|
"about:blank",
|
||||||
|
nullptr,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (execvp("./_deps/lagom-build/headless-browser", const_cast<char**>(argv)) < 0)
|
||||||
|
perror("execvp");
|
||||||
|
} else {
|
||||||
char const* argv[] = {
|
char const* argv[] = {
|
||||||
"ladybird",
|
"ladybird",
|
||||||
"--webdriver-fd-passing-socket",
|
"--webdriver-fd-passing-socket",
|
||||||
|
@ -60,6 +84,8 @@ ErrorOr<void> Session::start()
|
||||||
|
|
||||||
if (execvp("./ladybird", const_cast<char**>(argv)) < 0)
|
if (execvp("./ladybird", const_cast<char**>(argv)) < 0)
|
||||||
perror("execvp");
|
perror("execvp");
|
||||||
|
}
|
||||||
|
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace WebDriver {
|
||||||
|
|
||||||
class Session {
|
class Session {
|
||||||
public:
|
public:
|
||||||
Session(unsigned session_id, NonnullRefPtr<Client> client);
|
Session(unsigned session_id, NonnullRefPtr<Client> client, Web::WebDriver::LadybirdOptions options);
|
||||||
~Session();
|
~Session();
|
||||||
|
|
||||||
unsigned session_id() const { return m_id; }
|
unsigned session_id() const { return m_id; }
|
||||||
|
@ -35,8 +35,11 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NonnullRefPtr<Client> m_client;
|
NonnullRefPtr<Client> m_client;
|
||||||
|
Web::WebDriver::LadybirdOptions m_options;
|
||||||
|
|
||||||
bool m_started { false };
|
bool m_started { false };
|
||||||
unsigned m_id { 0 };
|
unsigned m_id { 0 };
|
||||||
|
|
||||||
RefPtr<WebContentConnection> m_web_content_connection;
|
RefPtr<WebContentConnection> m_web_content_connection;
|
||||||
Optional<pid_t> m_browser_pid;
|
Optional<pid_t> m_browser_pid;
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#define AK_DONT_REPLACE_STD
|
#define AK_DONT_REPLACE_STD
|
||||||
|
|
||||||
|
#include "../Utilities.h"
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/EventLoop.h>
|
#include <LibCore/EventLoop.h>
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
|
@ -36,6 +37,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
platform_init();
|
||||||
|
|
||||||
Core::EventLoop loop;
|
Core::EventLoop loop;
|
||||||
auto server = TRY(Core::TCPServer::try_create());
|
auto server = TRY(Core::TCPServer::try_create());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue