From 31bdd8a918b5146c19495e02bd48e4de8187f2e3 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 13 Mar 2023 07:50:26 -0400 Subject: [PATCH] headless-browser: Massage URLs a bit before loading This is to mimic what Ladybird and Browser do before trying to load the URL. --- Userland/Utilities/headless-browser.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp index dc3f18d7a49..b6ef2c25039 100644 --- a/Userland/Utilities/headless-browser.cpp +++ b/Userland/Utilities/headless-browser.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -159,6 +160,15 @@ static ErrorOr> load_page_for_screenshot_and_exit(Cor return timer; } +static ErrorOr format_url(StringView url) +{ + URL formatted_url { url }; + if (!formatted_url.is_valid()) + formatted_url = TRY(String::formatted("http://{}", url)); + + return formatted_url; +} + ErrorOr serenity_main(Main::Arguments arguments) { #if !defined(AK_OS_SERENITY) @@ -193,7 +203,7 @@ ErrorOr serenity_main(Main::Arguments arguments) static constexpr Gfx::IntSize window_size { 800, 600 }; auto view = TRY(HeadlessWebContentView::create(move(theme), window_size, web_driver_ipc_path)); - view->load(URL { url }); + view->load(TRY(format_url(url))); RefPtr timer; if (web_driver_ipc_path.is_empty())