summaryrefslogtreecommitdiff
path: root/Userland/Utilities/headless-browser.cpp
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-03-13 07:50:26 -0400
committerLinus Groh <mail@linusgroh.de>2023-03-13 12:41:10 +0000
commit31bdd8a918b5146c19495e02bd48e4de8187f2e3 (patch)
tree6f621757f11ea1f5bf542d37968a527302c3b2f0 /Userland/Utilities/headless-browser.cpp
parent4420e48dc345262f5b92d0d117ebda1752263431 (diff)
downloadserenity-31bdd8a918b5146c19495e02bd48e4de8187f2e3.zip
headless-browser: Massage URLs a bit before loading
This is to mimic what Ladybird and Browser do before trying to load the URL.
Diffstat (limited to 'Userland/Utilities/headless-browser.cpp')
-rw-r--r--Userland/Utilities/headless-browser.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/Userland/Utilities/headless-browser.cpp b/Userland/Utilities/headless-browser.cpp
index dc3f18d7a4..b6ef2c2503 100644
--- a/Userland/Utilities/headless-browser.cpp
+++ b/Userland/Utilities/headless-browser.cpp
@@ -15,6 +15,7 @@
#include <AK/DeprecatedString.h>
#include <AK/LexicalPath.h>
#include <AK/NonnullOwnPtr.h>
+#include <AK/String.h>
#include <AK/URL.h>
#include <AK/Vector.h>
#include <LibCore/ArgsParser.h>
@@ -159,6 +160,15 @@ static ErrorOr<NonnullRefPtr<Core::Timer>> load_page_for_screenshot_and_exit(Cor
return timer;
}
+static ErrorOr<URL> format_url(StringView url)
+{
+ URL formatted_url { url };
+ if (!formatted_url.is_valid())
+ formatted_url = TRY(String::formatted("http://{}", url));
+
+ return formatted_url;
+}
+
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
#if !defined(AK_OS_SERENITY)
@@ -193,7 +203,7 @@ ErrorOr<int> 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<Core::Timer> timer;
if (web_driver_ipc_path.is_empty())