diff --git a/Ladybird/WebDriver/CMakeLists.txt b/Ladybird/WebDriver/CMakeLists.txt index 1719ac2a59..f10b05ada0 100644 --- a/Ladybird/WebDriver/CMakeLists.txt +++ b/Ladybird/WebDriver/CMakeLists.txt @@ -5,6 +5,7 @@ set(SOURCES ${WEBDRIVER_SOURCE_DIR}/Session.cpp ${WEBDRIVER_SOURCE_DIR}/WebContentConnection.cpp ../Utilities.cpp + ../HelperProcess.cpp main.cpp ) diff --git a/Ladybird/WebDriver/main.cpp b/Ladybird/WebDriver/main.cpp index a69e666447..03f11e418b 100644 --- a/Ladybird/WebDriver/main.cpp +++ b/Ladybird/WebDriver/main.cpp @@ -6,6 +6,7 @@ #define AK_DONT_REPLACE_STD +#include "../HelperProcess.h" #include "../Utilities.h" #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include #if defined(AK_OS_MACOS) @@ -33,6 +35,21 @@ static char** environment() #endif } +static ErrorOr launch_process(StringView application, char const* argv[]) +{ + auto paths = TRY(get_paths_for_helper_process(application)); + + ErrorOr result = -1; + for (auto const& path : paths) { + auto path_view = path.bytes_as_string_view(); + argv[0] = path_view.characters_without_null_termination(); + result = Core::System::posix_spawn(path_view, nullptr, nullptr, const_cast(argv), environment()); + if (!result.is_error()) + break; + } + return result; +} + static ErrorOr launch_browser(DeprecatedString const& socket_path) { char const* argv[] = { @@ -42,7 +59,7 @@ static ErrorOr launch_browser(DeprecatedString const& socket_path) nullptr, }; - return Core::System::posix_spawn("./ladybird"sv, nullptr, nullptr, const_cast(argv), environment()); + return launch_process("ladybird"sv, argv); } static ErrorOr launch_headless_browser(DeprecatedString const& socket_path) @@ -65,11 +82,14 @@ static ErrorOr launch_headless_browser(DeprecatedString const& socket_pat nullptr, }; - return Core::System::posix_spawn("./_deps/lagom-build/headless-browser"sv, nullptr, nullptr, const_cast(argv), environment()); + return launch_process("headless-browser"sv, argv); } ErrorOr serenity_main(Main::Arguments arguments) { + // Note: only creating this to get access to its static methods in HelperProcess + QCoreApplication application(arguments.argc, arguments.argv); + auto listen_address = "0.0.0.0"sv; int port = 8000;