mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 23:59:49 +00:00
LibWebView: Add a command line option to override the User-Agent
This commit just adds a command line option to case-insensitively accept a User-Agent name to use as the UA override. The UIs will individually need to make use of this option.
This commit is contained in:
parent
a6bf253602
commit
a04327a0c9
Notes:
github-actions[bot]
2024-08-29 12:06:59 +00:00
Author: https://github.com/trflynn89
Commit: a04327a0c9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1215
Reviewed-by: https://github.com/tcl3 ✅
4 changed files with 27 additions and 0 deletions
|
@ -11,6 +11,7 @@
|
||||||
#include <LibImageDecoderClient/Client.h>
|
#include <LibImageDecoderClient/Client.h>
|
||||||
#include <LibWebView/Application.h>
|
#include <LibWebView/Application.h>
|
||||||
#include <LibWebView/URL.h>
|
#include <LibWebView/URL.h>
|
||||||
|
#include <LibWebView/UserAgent.h>
|
||||||
#include <LibWebView/WebContentClient.h>
|
#include <LibWebView/WebContentClient.h>
|
||||||
|
|
||||||
namespace WebView {
|
namespace WebView {
|
||||||
|
@ -59,6 +60,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
|
||||||
Optional<StringView> debug_process;
|
Optional<StringView> debug_process;
|
||||||
Optional<StringView> profile_process;
|
Optional<StringView> profile_process;
|
||||||
Optional<StringView> webdriver_content_ipc_path;
|
Optional<StringView> webdriver_content_ipc_path;
|
||||||
|
Optional<StringView> user_agent_preset;
|
||||||
bool log_all_js_exceptions = false;
|
bool log_all_js_exceptions = false;
|
||||||
bool enable_idl_tracing = false;
|
bool enable_idl_tracing = false;
|
||||||
bool enable_http_cache = false;
|
bool enable_http_cache = false;
|
||||||
|
@ -83,6 +85,16 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
|
||||||
args_parser.add_option(expose_internals_object, "Expose internals object", "expose-internals-object");
|
args_parser.add_option(expose_internals_object, "Expose internals object", "expose-internals-object");
|
||||||
args_parser.add_option(force_cpu_painting, "Force CPU painting", "force-cpu-painting");
|
args_parser.add_option(force_cpu_painting, "Force CPU painting", "force-cpu-painting");
|
||||||
args_parser.add_option(force_fontconfig, "Force using fontconfig for font loading", "force-fontconfig");
|
args_parser.add_option(force_fontconfig, "Force using fontconfig for font loading", "force-fontconfig");
|
||||||
|
args_parser.add_option(Core::ArgsParser::Option {
|
||||||
|
.argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
|
||||||
|
.help_string = "Name of the User-Agent preset to use in place of the default User-Agent",
|
||||||
|
.long_name = "user-agent-preset",
|
||||||
|
.value_name = "name",
|
||||||
|
.accept_value = [&](StringView value) {
|
||||||
|
user_agent_preset = normalize_user_agent_name(value);
|
||||||
|
return user_agent_preset.has_value();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
create_platform_arguments(args_parser);
|
create_platform_arguments(args_parser);
|
||||||
args_parser.parse(arguments);
|
args_parser.parse(arguments);
|
||||||
|
@ -114,6 +126,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_
|
||||||
m_web_content_options = {
|
m_web_content_options = {
|
||||||
.command_line = MUST(String::join(' ', arguments.strings)),
|
.command_line = MUST(String::join(' ', arguments.strings)),
|
||||||
.executable_path = MUST(String::from_byte_string(MUST(Core::System::current_executable_path()))),
|
.executable_path = MUST(String::from_byte_string(MUST(Core::System::current_executable_path()))),
|
||||||
|
.user_agent_preset = move(user_agent_preset),
|
||||||
.log_all_js_exceptions = log_all_js_exceptions ? LogAllJSExceptions::Yes : LogAllJSExceptions::No,
|
.log_all_js_exceptions = log_all_js_exceptions ? LogAllJSExceptions::Yes : LogAllJSExceptions::No,
|
||||||
.enable_idl_tracing = enable_idl_tracing ? EnableIDLTracing::Yes : EnableIDLTracing::No,
|
.enable_idl_tracing = enable_idl_tracing ? EnableIDLTracing::Yes : EnableIDLTracing::No,
|
||||||
.enable_http_cache = enable_http_cache ? EnableHTTPCache::Yes : EnableHTTPCache::No,
|
.enable_http_cache = enable_http_cache ? EnableHTTPCache::Yes : EnableHTTPCache::No,
|
||||||
|
|
|
@ -93,6 +93,7 @@ struct WebContentOptions {
|
||||||
String command_line;
|
String command_line;
|
||||||
String executable_path;
|
String executable_path;
|
||||||
Optional<ByteString> config_path {};
|
Optional<ByteString> config_path {};
|
||||||
|
Optional<StringView> user_agent_preset {};
|
||||||
IsLayoutTestMode is_layout_test_mode { IsLayoutTestMode::No };
|
IsLayoutTestMode is_layout_test_mode { IsLayoutTestMode::No };
|
||||||
UseLagomNetworking use_lagom_networking { UseLagomNetworking::Yes };
|
UseLagomNetworking use_lagom_networking { UseLagomNetworking::Yes };
|
||||||
LogAllJSExceptions log_all_js_exceptions { LogAllJSExceptions::No };
|
LogAllJSExceptions log_all_js_exceptions { LogAllJSExceptions::No };
|
||||||
|
|
|
@ -19,4 +19,14 @@ OrderedHashMap<StringView, StringView> const user_agents = {
|
||||||
{ "Safari iOS Mobile"sv, "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1"sv },
|
{ "Safari iOS Mobile"sv, "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1"sv },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Optional<StringView> normalize_user_agent_name(StringView name)
|
||||||
|
{
|
||||||
|
for (auto const& user_agent : user_agents) {
|
||||||
|
if (user_agent.key.equals_ignoring_ascii_case(name))
|
||||||
|
return user_agent.key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/HashMap.h>
|
#include <AK/HashMap.h>
|
||||||
|
#include <AK/Optional.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
|
||||||
namespace WebView {
|
namespace WebView {
|
||||||
|
|
||||||
extern OrderedHashMap<StringView, StringView> const user_agents;
|
extern OrderedHashMap<StringView, StringView> const user_agents;
|
||||||
|
|
||||||
|
Optional<StringView> normalize_user_agent_name(StringView);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue