mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:57:44 +00:00
Ladybird: Implement WebDriver for Ladybird :^)
This adds a WebDriver binary for Ladybird to make use of Serenity's WebDriver implementation. This has to use the same IPC socket handling that was used to make WebContent work out-of-process. Besides that, we are able to reuse almost everything from Serenity.
This commit is contained in:
parent
54321f49ad
commit
9e0db602ca
6 changed files with 238 additions and 2 deletions
67
Ladybird/WebDriver/main.cpp
Normal file
67
Ladybird/WebDriver/main.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#define AK_DONT_REPLACE_STD
|
||||
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibCore/TCPServer.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <WebDriver/Client.h>
|
||||
|
||||
extern String s_serenity_resource_root;
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
auto listen_address = "0.0.0.0"sv;
|
||||
int port = 8000;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_option(listen_address, "IP address to listen on", "listen-address", 'l', "listen_address");
|
||||
args_parser.add_option(port, "Port to listen on", "port", 'p', "port");
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto ipv4_address = IPv4Address::from_string(listen_address);
|
||||
if (!ipv4_address.has_value()) {
|
||||
warnln("Invalid listen address: {}", listen_address);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((u16)port != port) {
|
||||
warnln("Invalid port number: {}", port);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Core::EventLoop loop;
|
||||
auto server = TRY(Core::TCPServer::try_create());
|
||||
|
||||
// FIXME: Propagate errors
|
||||
server->on_ready_to_accept = [&] {
|
||||
auto maybe_client_socket = server->accept();
|
||||
if (maybe_client_socket.is_error()) {
|
||||
warnln("Failed to accept the client: {}", maybe_client_socket.error());
|
||||
return;
|
||||
}
|
||||
|
||||
auto maybe_buffered_socket = Core::Stream::BufferedTCPSocket::create(maybe_client_socket.release_value());
|
||||
if (maybe_buffered_socket.is_error()) {
|
||||
warnln("Could not obtain a buffered socket for the client: {}", maybe_buffered_socket.error());
|
||||
return;
|
||||
}
|
||||
|
||||
auto maybe_client = WebDriver::Client::try_create(maybe_buffered_socket.release_value(), server);
|
||||
if (maybe_client.is_error()) {
|
||||
warnln("Could not create a WebDriver client: {}", maybe_client.error());
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
TRY(server->listen(ipv4_address.value(), port, Core::TCPServer::AllowAddressReuse::Yes));
|
||||
outln("Listening on {}:{}", ipv4_address.value(), port);
|
||||
|
||||
return loop.exec();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue