mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 12:49:19 +00:00
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:
parent
a67018b2fc
commit
b24a7079f1
Notes:
github-actions[bot]
2024-10-22 03:25:32 +00:00
Author: https://github.com/trflynn89
Commit: b24a7079f1
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1907
Reviewed-by: https://github.com/tcl3 ✅
3 changed files with 19 additions and 1 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include <LibCore/System.h>
|
#include <LibCore/System.h>
|
||||||
#include <LibCore/TCPServer.h>
|
#include <LibCore/TCPServer.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
|
#include <LibWeb/WebDriver/Capabilities.h>
|
||||||
#include <WebDriver/Client.h>
|
#include <WebDriver/Client.h>
|
||||||
|
|
||||||
static Vector<ByteString> certificates;
|
static Vector<ByteString> certificates;
|
||||||
|
@ -74,12 +75,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
auto listen_address = "0.0.0.0"sv;
|
auto listen_address = "0.0.0.0"sv;
|
||||||
int port = 8000;
|
int port = 8000;
|
||||||
bool force_cpu_painting = false;
|
bool force_cpu_painting = false;
|
||||||
|
bool headless = false;
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_option(listen_address, "IP address to listen on", "listen-address", 'l', "listen_address");
|
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(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(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(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);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
auto ipv4_address = IPv4Address::from_string(listen_address);
|
auto ipv4_address = IPv4Address::from_string(listen_address);
|
||||||
|
@ -95,6 +98,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
platform_init();
|
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()));
|
auto webdriver_socket_path = ByteString::formatted("{}/webdriver", TRY(Core::StandardPaths::runtime_directory()));
|
||||||
TRY(Core::Directory::create(webdriver_socket_path, Core::Directory::CreateDirectories::Yes));
|
TRY(Core::Directory::create(webdriver_socket_path, Core::Directory::CreateDirectories::Yes));
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,13 @@ static ErrorOr<JsonObject, Error> deserialize_as_a_proxy(JsonValue parameter)
|
||||||
return proxy;
|
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)
|
static Response deserialize_as_ladybird_options(JsonValue value)
|
||||||
{
|
{
|
||||||
if (!value.is_object())
|
if (!value.is_object())
|
||||||
|
@ -88,7 +95,7 @@ static Response deserialize_as_ladybird_options(JsonValue value)
|
||||||
static JsonObject default_ladybird_options()
|
static JsonObject default_ladybird_options()
|
||||||
{
|
{
|
||||||
JsonObject options;
|
JsonObject options;
|
||||||
options.set("headless"sv, false);
|
options.set("headless"sv, default_interface_mode == InterfaceMode::Headless);
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,12 @@ constexpr UnhandledPromptBehavior unhandled_prompt_behavior_from_string(StringVi
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class InterfaceMode {
|
||||||
|
Graphical,
|
||||||
|
Headless,
|
||||||
|
};
|
||||||
|
void set_default_interface_mode(InterfaceMode);
|
||||||
|
|
||||||
struct LadybirdOptions {
|
struct LadybirdOptions {
|
||||||
explicit LadybirdOptions(JsonObject const& capabilities);
|
explicit LadybirdOptions(JsonObject const& capabilities);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue