diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp index ab2aba6a137..33ec90966df 100644 --- a/Libraries/LibWebView/Application.cpp +++ b/Libraries/LibWebView/Application.cpp @@ -70,7 +70,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_ bool allow_popups = false; bool disable_scripting = false; bool disable_sql_database = false; - Optional devtools_port; + u16 devtools_port = WebView::default_devtools_port; Optional debug_process; Optional profile_process; Optional webdriver_content_ipc_path; @@ -101,7 +101,7 @@ void Application::initialize(Main::Arguments const& arguments, URL::URL new_tab_ args_parser.add_option(debug_process, "Wait for a debugger to attach to the given process name (WebContent, RequestServer, etc.)", "debug-process", 0, "process-name"); args_parser.add_option(profile_process, "Enable callgrind profiling of the given process name (WebContent, RequestServer, etc.)", "profile-process", 0, "process-name"); args_parser.add_option(webdriver_content_ipc_path, "Path to WebDriver IPC for WebContent", "webdriver-content-path", 0, "path", Core::ArgsParser::OptionHideMode::CommandLineAndMarkdown); - args_parser.add_option(devtools_port, "Set the Firefox DevTools port (EXPERIMENTAL)", "devtools", 0, "port"); + args_parser.add_option(devtools_port, "Set the Firefox DevTools server port ", "devtools-port", 0, "port"); args_parser.add_option(log_all_js_exceptions, "Log all JavaScript exceptions", "log-all-js-exceptions"); args_parser.add_option(disable_site_isolation, "Disable site isolation", "disable-site-isolation"); args_parser.add_option(enable_idl_tracing, "Enable IDL tracing", "enable-idl-tracing"); @@ -252,7 +252,6 @@ ErrorOr Application::launch_services() { TRY(launch_request_server()); TRY(launch_image_decoder_server()); - TRY(launch_devtools_server()); return {}; } @@ -293,8 +292,8 @@ ErrorOr Application::launch_image_decoder_server() ErrorOr Application::launch_devtools_server() { - if (m_chrome_options.devtools_port.has_value()) - m_devtools = TRY(DevTools::DevToolsServer::create(*this, *m_chrome_options.devtools_port)); + VERIFY(!m_devtools); + m_devtools = TRY(DevTools::DevToolsServer::create(*this, m_chrome_options.devtools_port)); return {}; } @@ -385,6 +384,17 @@ ErrorOr Application::path_for_downloaded_file(StringView file) cons return LexicalPath::join(downloads_directory, file); } +ErrorOr Application::toggle_devtools_enabled() +{ + if (m_devtools) { + m_devtools.clear(); + return DevtoolsState::Disabled; + } + + TRY(launch_devtools_server()); + return DevtoolsState::Enabled; +} + void Application::refresh_tab_list() { if (!m_devtools) diff --git a/Libraries/LibWebView/Application.h b/Libraries/LibWebView/Application.h index 83c77847b88..41bf07e276b 100644 --- a/Libraries/LibWebView/Application.h +++ b/Libraries/LibWebView/Application.h @@ -62,6 +62,11 @@ public: ErrorOr path_for_downloaded_file(StringView file) const; + enum class DevtoolsState { + Disabled, + Enabled, + }; + ErrorOr toggle_devtools_enabled(); void refresh_tab_list(); protected: diff --git a/Libraries/LibWebView/Options.h b/Libraries/LibWebView/Options.h index 390686ab80e..a011ce415a7 100644 --- a/Libraries/LibWebView/Options.h +++ b/Libraries/LibWebView/Options.h @@ -57,6 +57,8 @@ struct DNSOverUDP { using DNSSettings = Variant; +constexpr inline u16 default_devtools_port = 6000; + struct ChromeOptions { Vector urls; Vector raw_urls; @@ -71,7 +73,7 @@ struct ChromeOptions { Optional profile_helper_process {}; Optional webdriver_content_ipc_path {}; DNSSettings dns_settings { SystemDNS {} }; - Optional devtools_port; + u16 devtools_port { default_devtools_port }; }; enum class IsLayoutTestMode {