refactor(webdriver): move webdriver_port option to servoshell pref (#37867)

Move `webdriver_port` option from servo config options to servoshell
preference.

Testing: run `./mach run` with/without `--webdriver` option and see if
the webdriver server runs on the port (default: 7000)
Fixes: https://github.com/servo/servo/issues/37843

Signed-off-by: Jason Tsai <git@pews.dev>
This commit is contained in:
Jason Tsai 2025-07-04 16:04:49 +09:00 committed by GitHub
parent 6ba54e4d79
commit cf408f7302
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 14 additions and 15 deletions

View file

@ -44,10 +44,6 @@ pub struct Opts {
/// behavior for debugging purposes. /// behavior for debugging purposes.
pub debug: DebugOptions, pub debug: DebugOptions,
/// `None` to disable WebDriver or `Some` with a port number to start a server to listen to
/// remote WebDriver commands.
pub webdriver_port: Option<u16>,
/// Whether we're running in multiprocess mode. /// Whether we're running in multiprocess mode.
pub multiprocess: bool, pub multiprocess: bool,
@ -192,7 +188,6 @@ impl Default for Opts {
nonincremental_layout: false, nonincremental_layout: false,
user_stylesheets: Vec::new(), user_stylesheets: Vec::new(),
hard_fail: true, hard_fail: true,
webdriver_port: None,
multiprocess: false, multiprocess: false,
background_hang_monitor: false, background_hang_monitor: false,
random_pipeline_closure_probability: None, random_pipeline_closure_probability: None,

View file

@ -160,7 +160,7 @@ impl App {
servo.setup_logging(); servo.setup_logging();
// Initialize WebDriver server here before `servo` is moved. // Initialize WebDriver server here before `servo` is moved.
let webdriver_receiver = self.opts.webdriver_port.map(|port| { let webdriver_receiver = self.servoshell_preferences.webdriver_port.map(|port| {
let (embedder_sender, embedder_receiver) = unbounded(); let (embedder_sender, embedder_receiver) = unbounded();
// TODO: WebDriver will no longer need this channel once all WebDriver // TODO: WebDriver will no longer need this channel once all WebDriver

View file

@ -12,7 +12,7 @@ use euclid::Vector2D;
use keyboard_types::{Key, Modifiers, ShortcutMatcher}; use keyboard_types::{Key, Modifiers, ShortcutMatcher};
use log::{error, info}; use log::{error, info};
use servo::base::id::WebViewId; use servo::base::id::WebViewId;
use servo::config::{opts, pref}; use servo::config::pref;
use servo::ipc_channel::ipc::IpcSender; use servo::ipc_channel::ipc::IpcSender;
use servo::webrender_api::ScrollLocation; use servo::webrender_api::ScrollLocation;
use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize}; use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize};
@ -500,7 +500,7 @@ impl WebViewDelegate for RunningAppState {
// When WebDriver is enabled, do not focus and raise the WebView to the top, // When WebDriver is enabled, do not focus and raise the WebView to the top,
// as that is what the specification expects. Otherwise, we would like `window.open()` // as that is what the specification expects. Otherwise, we would like `window.open()`
// to create a new foreground tab // to create a new foreground tab
if opts::get().webdriver_port.is_none() { if self.servoshell_preferences.webdriver_port.is_none() {
webview.focus(); webview.focus();
webview.raise_to_top(true); webview.raise_to_top(true);
} }

View file

@ -57,6 +57,9 @@ pub(crate) struct ServoShellPreferences {
/// Where to load userscripts from, if any. /// Where to load userscripts from, if any.
/// and if the option isn't passed userscripts won't be loaded. /// and if the option isn't passed userscripts won't be loaded.
pub userscripts_directory: Option<PathBuf>, pub userscripts_directory: Option<PathBuf>,
/// `None` to disable WebDriver or `Some` with a port number to start a server to listen to
/// remote WebDriver commands.
pub webdriver_port: Option<u16>,
/// Log filter given in the `log_filter` spec as a String, if any. /// Log filter given in the `log_filter` spec as a String, if any.
/// If a filter is passed, the logger should adjust accordingly. /// If a filter is passed, the logger should adjust accordingly.
@ -84,6 +87,7 @@ impl Default for ServoShellPreferences {
output_image_path: None, output_image_path: None,
exit_after_stable_image: false, exit_after_stable_image: false,
userscripts_directory: None, userscripts_directory: None,
webdriver_port: None,
#[cfg(target_env = "ohos")] #[cfg(target_env = "ohos")]
log_filter: None, log_filter: None,
#[cfg(target_env = "ohos")] #[cfg(target_env = "ohos")]
@ -535,12 +539,6 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
preferences.devtools_server_port = port; preferences.devtools_server_port = port;
} }
let webdriver_port = opt_match.opt_default("webdriver", "7000").map(|port| {
port.parse().unwrap_or_else(|err| {
args_fail(&format!("Error parsing option: --webdriver ({})", err))
})
});
let parse_resolution_string = |string: String| { let parse_resolution_string = |string: String| {
let components: Vec<u32> = string let components: Vec<u32> = string
.split('x') .split('x')
@ -646,6 +644,12 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
preferences.js_ion_enabled = false; preferences.js_ion_enabled = false;
} }
let webdriver_port = opt_match.opt_default("webdriver", "7000").map(|port| {
port.parse().unwrap_or_else(|err| {
args_fail(&format!("Error parsing option: --webdriver ({})", err))
})
});
let exit_after_load = opt_match.opt_present("x") || output_image_path.is_some(); let exit_after_load = opt_match.opt_present("x") || output_image_path.is_some();
let wait_for_stable_image = exit_after_load; let wait_for_stable_image = exit_after_load;
let servoshell_preferences = ServoShellPreferences { let servoshell_preferences = ServoShellPreferences {
@ -662,6 +666,7 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
userscripts_directory: opt_match userscripts_directory: opt_match
.opt_default("userscripts", "resources/user-agent-js") .opt_default("userscripts", "resources/user-agent-js")
.map(PathBuf::from), .map(PathBuf::from),
webdriver_port,
#[cfg(target_env = "ohos")] #[cfg(target_env = "ohos")]
log_filter, log_filter,
#[cfg(target_env = "ohos")] #[cfg(target_env = "ohos")]
@ -686,7 +691,6 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
nonincremental_layout, nonincremental_layout,
user_stylesheets, user_stylesheets,
hard_fail: opt_match.opt_present("f") && !opt_match.opt_present("F"), hard_fail: opt_match.opt_present("f") && !opt_match.opt_present("F"),
webdriver_port,
multiprocess: opt_match.opt_present("M"), multiprocess: opt_match.opt_present("M"),
background_hang_monitor: opt_match.opt_present("B"), background_hang_monitor: opt_match.opt_present("B"),
sandbox: opt_match.opt_present("S"), sandbox: opt_match.opt_present("S"),