diff --git a/Services/WebDriver/main.cpp b/Services/WebDriver/main.cpp index 4bf0d61c7b7..c1a3fd69f12 100644 --- a/Services/WebDriver/main.cpp +++ b/Services/WebDriver/main.cpp @@ -33,7 +33,7 @@ static ErrorOr launch_process(StringView application, ReadonlySpa return result; } -static Vector create_arguments(ByteString const& socket_path, bool force_cpu_painting) +static Vector create_arguments(ByteString const& socket_path, bool force_cpu_painting, Optional debug_process) { Vector arguments { "--webdriver-content-path"sv, @@ -52,19 +52,23 @@ static Vector create_arguments(ByteString const& socket_path, bool f if (force_cpu_painting) arguments.append("--force-cpu-painting"sv); + dbgln("Debug process: {}", debug_process); + if (debug_process.has_value()) + arguments.append(ByteString::formatted("--debug-process={}", debug_process.value())); + arguments.append("about:blank"sv); return arguments; } -static ErrorOr launch_browser(ByteString const& socket_path, bool force_cpu_painting) +static ErrorOr launch_browser(ByteString const& socket_path, bool force_cpu_painting, Optional debug_process) { - auto arguments = create_arguments(socket_path, force_cpu_painting); + auto arguments = create_arguments(socket_path, force_cpu_painting, move(debug_process)); return launch_process("Ladybird"sv, arguments.span()); } -static ErrorOr launch_headless_browser(ByteString const& socket_path, bool force_cpu_painting) +static ErrorOr launch_headless_browser(ByteString const& socket_path, bool force_cpu_painting, Optional debug_process) { - auto arguments = create_arguments(socket_path, force_cpu_painting); + auto arguments = create_arguments(socket_path, force_cpu_painting, move(debug_process)); return launch_process("headless-browser"sv, arguments.span()); } @@ -76,12 +80,14 @@ ErrorOr serenity_main(Main::Arguments arguments) int port = 8000; bool force_cpu_painting = false; bool headless = false; + Optional debug_process; 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(debug_process, "Wait for a debugger to attach to the given process name (WebContent, RequestServer, etc.)", "debug-process", 0, "process-name"); args_parser.add_option(headless, "Launch browser without a graphical interface", "headless"); args_parser.parse(arguments); @@ -121,11 +127,11 @@ ErrorOr serenity_main(Main::Arguments arguments) } auto launch_browser_callback = [&](ByteString const& socket_path) { - return launch_browser(socket_path, force_cpu_painting); + return launch_browser(socket_path, force_cpu_painting, debug_process); }; auto launch_headless_browser_callback = [&](ByteString const& socket_path) { - return launch_headless_browser(socket_path, force_cpu_painting); + return launch_headless_browser(socket_path, force_cpu_painting, debug_process); }; auto maybe_client = WebDriver::Client::try_create(maybe_buffered_socket.release_value(), { move(launch_browser_callback), move(launch_headless_browser_callback) }, server);