LibWeb+WebDriver: Add a flag to default WebDriver to headless mode

We previously only supported enabling headless mode on a per-session
basis via the capabilities record. We don't have the ability to mutate
this record from WPT, so this adds a flag to set the default mode.
This commit is contained in:
Timothy Flynn 2024-10-21 19:07:55 -04:00 committed by Tim Ledbetter
parent a67018b2fc
commit b24a7079f1
Notes: github-actions[bot] 2024-10-22 03:25:32 +00:00
3 changed files with 19 additions and 1 deletions

View file

@ -14,6 +14,7 @@
#include <LibCore/System.h>
#include <LibCore/TCPServer.h>
#include <LibMain/Main.h>
#include <LibWeb/WebDriver/Capabilities.h>
#include <WebDriver/Client.h>
static Vector<ByteString> certificates;
@ -74,12 +75,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto listen_address = "0.0.0.0"sv;
int port = 8000;
bool force_cpu_painting = false;
bool headless = false;
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.add_option(certificates, "Path to a certificate file", "certificate", 'C', "certificate");
args_parser.add_option(force_cpu_painting, "Launch browser with GPU painting disabled", "force-cpu-painting");
args_parser.add_option(headless, "Launch browser without a graphical interface", "headless");
args_parser.parse(arguments);
auto ipv4_address = IPv4Address::from_string(listen_address);
@ -95,6 +98,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
platform_init();
Web::WebDriver::set_default_interface_mode(headless ? Web::WebDriver::InterfaceMode::Headless : Web::WebDriver::InterfaceMode::Graphical);
auto webdriver_socket_path = ByteString::formatted("{}/webdriver", TRY(Core::StandardPaths::runtime_directory()));
TRY(Core::Directory::create(webdriver_socket_path, Core::Directory::CreateDirectories::Yes));

View file

@ -72,6 +72,13 @@ static ErrorOr<JsonObject, Error> deserialize_as_a_proxy(JsonValue parameter)
return proxy;
}
static InterfaceMode default_interface_mode { InterfaceMode::Graphical };
void set_default_interface_mode(InterfaceMode interface_mode)
{
default_interface_mode = interface_mode;
}
static Response deserialize_as_ladybird_options(JsonValue value)
{
if (!value.is_object())
@ -88,7 +95,7 @@ static Response deserialize_as_ladybird_options(JsonValue value)
static JsonObject default_ladybird_options()
{
JsonObject options;
options.set("headless"sv, false);
options.set("headless"sv, default_interface_mode == InterfaceMode::Headless);
return options;
}

View file

@ -54,6 +54,12 @@ constexpr UnhandledPromptBehavior unhandled_prompt_behavior_from_string(StringVi
VERIFY_NOT_REACHED();
}
enum class InterfaceMode {
Graphical,
Headless,
};
void set_default_interface_mode(InterfaceMode);
struct LadybirdOptions {
explicit LadybirdOptions(JsonObject const& capabilities);