From 1653c5ea417773e15d4d4ff05a064ba0558e3b9d Mon Sep 17 00:00:00 2001 From: auipc <139733387+auipc@users.noreply.github.com> Date: Sat, 12 Aug 2023 12:57:10 -0400 Subject: [PATCH] LibWeb: Use current platform for navigator.platform Before, navigator.platform would always report the platform as "Serenity OS", regardless of whether or not that was true. It also did not include the architecture, which Firefox and Chrome both do. Now, it can report either "Linux x86_64" or "SerenityOS AArch64". --- Userland/Libraries/LibWeb/HTML/NavigatorID.cpp | 2 +- Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp | 1 + Userland/Libraries/LibWeb/Loader/ResourceLoader.h | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/HTML/NavigatorID.cpp b/Userland/Libraries/LibWeb/HTML/NavigatorID.cpp index c338dd6ea6..c757f86bf7 100644 --- a/Userland/Libraries/LibWeb/HTML/NavigatorID.cpp +++ b/Userland/Libraries/LibWeb/HTML/NavigatorID.cpp @@ -40,7 +40,7 @@ DeprecatedString NavigatorIDMixin::platform() const // platform. // FIXME: Use some portion of the user agent string to make spoofing work 100% - return "SerenityOS"; + return ResourceLoader::the().platform(); } // https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator-useragent diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp index 9bdfcfa6ae..d251851835 100644 --- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp @@ -58,6 +58,7 @@ ErrorOr> ResourceLoader::try_create(NonnullRefPtr< ResourceLoader::ResourceLoader(NonnullRefPtr connector) : m_connector(move(connector)) , m_user_agent(default_user_agent) + , m_platform(default_platform) { } diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.h b/Userland/Libraries/LibWeb/Loader/ResourceLoader.h index 1c79de08d5..fc36ba4f5f 100644 --- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.h +++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.h @@ -50,6 +50,7 @@ namespace Web { #define BROWSER_VERSION "1.0" constexpr auto default_user_agent = "Mozilla/5.0 (" OS_STRING "; " CPU_STRING ") LibWeb+LibJS/1.0 " BROWSER_NAME "/" BROWSER_VERSION ""sv; +constexpr auto default_platform = OS_STRING " " CPU_STRING ""sv; class ResourceLoaderConnectorRequest : public RefCounted { public: @@ -110,6 +111,9 @@ public: DeprecatedString const& user_agent() const { return m_user_agent; } void set_user_agent(DeprecatedString const& user_agent) { m_user_agent = user_agent; } + DeprecatedString const& platform() const { return m_platform; } + void set_platform(DeprecatedString const& platform) { m_platform = platform; } + void clear_cache(); void evict_from_cache(LoadRequest const&); @@ -124,6 +128,7 @@ private: HashTable> m_active_requests; NonnullRefPtr m_connector; DeprecatedString m_user_agent; + DeprecatedString m_platform; Optional m_page {}; };