Skip to content

Truly independent web browser

Meta+LibCore+LibWebCommon: Report a release's version in the browser

Jelle Raaijmakersed0a4c7e614f
diff --git a/Libraries/LibCore/BrowserVersion.h.in b/Libraries/LibCore/BrowserVersion.h.in
new file mode 100644
index 00000000000..05ebb8661ed
--- /dev/null
+++ b/Libraries/LibCore/BrowserVersion.h.in
@@ -0,0 +1,9 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#define BROWSER_VERSION "@LADYBIRD_BROWSER_VERSION@"
diff --git a/Libraries/LibCore/CMakeLists.txt b/Libraries/LibCore/CMakeLists.txt
index bae4425946a..81b21f72748 100644
--- a/Libraries/LibCore/CMakeLists.txt
+++ b/Libraries/LibCore/CMakeLists.txt
@@ -115,6 +115,12 @@ endif()
ladybird_lib(LibCore core EXPLICIT_SYMBOL_EXPORT)
target_link_libraries(LibCore PRIVATE Threads::Threads LibUnicode LibTextCodec mimalloc)
+configure_file(BrowserVersion.h.in BrowserVersion.h @ONLY)
+if (ENABLE_INSTALL_HEADERS)
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/BrowserVersion.h" COMPONENT Lagom_Development
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/LibCore")
+endif()
+
if (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
# NetBSD has its shm_open and shm_unlink functions in librt so we need to link that
target_link_libraries(LibCore PRIVATE rt)
diff --git a/Libraries/LibCore/Version.cpp b/Libraries/LibCore/Version.cpp
index 8a35601a199..e3e709a3e79 100644
--- a/Libraries/LibCore/Version.cpp
+++ b/Libraries/LibCore/Version.cpp
@@ -5,13 +5,14 @@
*/
#include <AK/String.h>
+#include <LibCore/BrowserVersion.h>
#include <LibCore/Version.h>
namespace Core::Version {
String read_long_version_string()
{
- return "Version 1.0"_string;
+ return "Version " BROWSER_VERSION ""_string;
}
}
diff --git a/Libraries/LibDevTools/Actors/DeviceActor.cpp b/Libraries/LibDevTools/Actors/DeviceActor.cpp
index 86400c5c217..ce85e34586b 100644
--- a/Libraries/LibDevTools/Actors/DeviceActor.cpp
+++ b/Libraries/LibDevTools/Actors/DeviceActor.cpp
@@ -6,6 +6,7 @@
#include <AK/JsonObject.h>
#include <AK/String.h>
+#include <LibCore/BrowserVersion.h>
#include <LibCore/Version.h>
#include <LibDevTools/Actors/DeviceActor.h>
#include <LibWebCommon/Loader/UserAgent.h>
diff --git a/Libraries/LibWebCommon/Loader/UserAgent.h b/Libraries/LibWebCommon/Loader/UserAgent.h
index d223988917a..eb9ee082370 100644
--- a/Libraries/LibWebCommon/Loader/UserAgent.h
+++ b/Libraries/LibWebCommon/Loader/UserAgent.h
@@ -11,6 +11,7 @@
#include <AK/String.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
+#include <LibCore/BrowserVersion.h>
#include <LibWebCommon/Loader/NavigatorCompatibilityMode.h>
namespace Web {
@@ -62,7 +63,6 @@ namespace Web {
#endif
#define BROWSER_NAME "Ladybird"
-#define BROWSER_VERSION "1.0"
// NB: Some web servers treat us very badly unless we pretend to be one of the major browsers.
// This token is appended to the User-Agent string to improve compatibility.
diff --git a/Libraries/LibWebCommon/WebDriver/Capabilities.cpp b/Libraries/LibWebCommon/WebDriver/Capabilities.cpp
index d9fbebcb40e..f4bc053be6f 100644
--- a/Libraries/LibWebCommon/WebDriver/Capabilities.cpp
+++ b/Libraries/LibWebCommon/WebDriver/Capabilities.cpp
@@ -9,6 +9,7 @@
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <AK/Optional.h>
+#include <LibCore/BrowserVersion.h>
#include <LibWebCommon/Loader/UserAgent.h>
#include <LibWebCommon/WebDriver/Capabilities.h>
#include <LibWebCommon/WebDriver/Proxy.h>
diff --git a/Libraries/LibWebView/CrashReport.cpp b/Libraries/LibWebView/CrashReport.cpp
index b20330f6e57..6ed4fc5c23e 100644
--- a/Libraries/LibWebView/CrashReport.cpp
+++ b/Libraries/LibWebView/CrashReport.cpp
@@ -7,6 +7,7 @@
#include <AK/CharacterTypes.h>
#include <AK/Hex.h>
#include <AK/StringBuilder.h>
+#include <LibCore/BrowserVersion.h>
#include <LibCore/CrashReportData.h>
#include <LibCore/StandardPaths.h>
#include <LibCore/System.h>
diff --git a/Libraries/LibWebView/WebCompatReport.cpp b/Libraries/LibWebView/WebCompatReport.cpp
index af54326a486..d5ca99a2bfc 100644
--- a/Libraries/LibWebView/WebCompatReport.cpp
+++ b/Libraries/LibWebView/WebCompatReport.cpp
@@ -7,6 +7,7 @@
#include <AK/Math.h>
#include <AK/StringBuilder.h>
#include <AK/WeakPtr.h>
+#include <LibCore/BrowserVersion.h>
#include <LibCore/ImmutableBytes.h>
#include <LibCore/Promise.h>
#include <LibWebCommon/Loader/UserAgent.h>
diff --git a/Libraries/LibWebView/WebUI/VersionUI.cpp b/Libraries/LibWebView/WebUI/VersionUI.cpp
index 4174ff2ccd8..2bdea345731 100644
--- a/Libraries/LibWebView/WebUI/VersionUI.cpp
+++ b/Libraries/LibWebView/WebUI/VersionUI.cpp
@@ -7,6 +7,7 @@
#include <AK/JsonObject.h>
#include <AK/NeverDestroyed.h>
#include <AK/String.h>
+#include <LibCore/BrowserVersion.h>
#include <LibCore/System.h>
#include <LibWebCommon/Loader/UserAgent.h>
#include <LibWebView/Application.h>
diff --git a/Tests/LibWeb/Text/input/Fetch/user-agent-client-hints.html b/Tests/LibWeb/Text/input/Fetch/user-agent-client-hints.html
index 460165ae2fb..2814440d7a0 100644
--- a/Tests/LibWeb/Text/input/Fetch/user-agent-client-hints.html
+++ b/Tests/LibWeb/Text/input/Fetch/user-agent-client-hints.html
@@ -31,7 +31,8 @@
// The build's own Chrome token, whatever this platform reports.
const version = navigator.userAgent.match(/Chrome\/(\d+)/)?.[1];
println(`own brands name Chromium at the User-Agent's version: ${brands.includes(`"Chromium";v="${version}"`) ? "PASS" : `FAIL (${brands})`}`);
- println(`own brands name Ladybird: ${brands.includes('"Ladybird";v="1"') ? "PASS" : `FAIL (${brands})`}`);
+ const ladybirdVersion = navigator.userAgent.match(/Ladybird\/(\d+)/)?.[1];
+ println(`own brands name Ladybird: ${brands.includes(`"Ladybird";v="${ladybirdVersion}"`) ? "PASS" : `FAIL (${brands})`}`);
println(`own mobile hint is a boolean: ${["?0", "?1"].includes(own("Sec-CH-UA-Mobile")) ? "PASS" : `FAIL (${own("Sec-CH-UA-Mobile")})`}`);
println(`own platform hint is quoted: ${/^".+"$/.test(own("Sec-CH-UA-Platform") ?? "") ? "PASS" : `FAIL (${own("Sec-CH-UA-Platform")})`}`);
diff --git a/Tests/LibWebView/TestWebCompatReport.cpp b/Tests/LibWebView/TestWebCompatReport.cpp
index 8b6e69d6b7f..1cd5522427c 100644
--- a/Tests/LibWebView/TestWebCompatReport.cpp
+++ b/Tests/LibWebView/TestWebCompatReport.cpp
@@ -10,6 +10,7 @@
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <AK/LexicalPath.h>
+#include <LibCore/BrowserVersion.h>
#include <LibCore/Environment.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Timer.h>
@@ -149,7 +150,7 @@ TEST_CASE(web_compat_report)
auto manifest = JsonValue::from_string(manifest_text).release_value().as_object();
VERIFY(manifest.get_string("kind"sv) == "web_compat"sv);
- VERIFY(manifest.get_string("client_version"sv) == "1.0"sv);
+ VERIFY(manifest.get_string("client_version"sv) == BROWSER_VERSION ""sv);
VERIFY(manifest_field(manifest, "description"sv)->as_string() == "The menu does not open"sv);
VERIFY(manifest_field(manifest, "url"sv)->as_string() == "https://example.com/broken?query"sv);
VERIFY(manifest_field(manifest, "user_agent"sv)->as_string() == "Mozilla/5.0 Ladybird/1.0"sv);