servoshell: Remove --userscripts option (#43573)

In #43182 it was [suggested to remove the
userscripts](https://github.com/servo/servo/pull/43182#issuecomment-4048383093)
option, since embedders can use the (new) `UserContentManager` API
instead.

Testing: This removes a commandline flag from servoshell. Existing tests
passing is sufficient.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
Jonathan Schwender
2026-03-23 19:39:57 +01:00
committed by GitHub
parent 0ee2b03b40
commit 64afd05d11
4 changed files with 1 additions and 54 deletions

View File

@@ -4,15 +4,12 @@
//! Application entry point, runs the event loop.
use std::path::Path;
use std::rc::Rc;
use std::time::Instant;
use std::{env, fs};
use servo::protocol_handler::ProtocolRegistry;
use servo::{
EventLoopWaker, Opts, Preferences, ServoBuilder, ServoUrl, UserContentManager, UserScript,
};
use servo::{EventLoopWaker, Opts, Preferences, ServoBuilder, ServoUrl, UserContentManager};
use url::Url;
use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
@@ -113,11 +110,6 @@ impl App {
servo.setup_logging();
let user_content_manager = Rc::new(UserContentManager::new(&servo));
for script in load_userscripts(self.servoshell_preferences.userscripts_directory.as_deref())
.expect("Loading userscripts failed")
{
user_content_manager.add_script(Rc::new(script));
}
for user_stylesheet in &self.servoshell_preferences.user_stylesheets {
user_content_manager.add_stylesheet(user_stylesheet.clone());
@@ -234,18 +226,3 @@ impl ApplicationHandler<AppEvent> for App {
event_loop.set_control_flow(ControlFlow::Wait);
}
}
fn load_userscripts(userscripts_directory: Option<&Path>) -> std::io::Result<Vec<UserScript>> {
let mut userscripts = Vec::new();
if let Some(userscripts_directory) = &userscripts_directory {
let mut files = std::fs::read_dir(userscripts_directory)?
.map(|e| e.map(|entry| entry.path()))
.collect::<Result<Vec<_>, _>>()?;
files.sort_unstable();
for file in files {
let script = std::fs::read_to_string(&file)?;
userscripts.push(UserScript::new(script, Some(file)));
}
}
Ok(userscripts)
}

View File

@@ -78,9 +78,6 @@ pub(crate) struct ServoShellPreferences {
pub output_image_path: Option<String>,
/// Whether or not to exit after Servo detects a stable output image in all WebViews.
pub exit_after_stable_image: bool,
/// Where to load userscripts from, if any.
/// and if the option isn't passed userscripts won't be loaded.
pub userscripts_directory: Option<PathBuf>,
/// A set of [`UserStylesheets`] to load for content.
pub user_stylesheets: Vec<Rc<UserStyleSheet>>,
/// `None` to disable WebDriver or `Some` with a port number to start a server to listen to
@@ -113,7 +110,6 @@ impl Default for ServoShellPreferences {
url: None,
output_image_path: None,
exit_after_stable_image: false,
userscripts_directory: None,
user_stylesheets: Default::default(),
webdriver_port: Cell::new(None),
#[cfg(target_env = "ohos")]
@@ -338,17 +334,6 @@ fn profile() -> impl Parser<Option<OutputOptions>> {
)
}
fn userscripts() -> impl Parser<Option<PathBuf>> {
flag_with_default_parser(
None,
"userscripts_directory",
"your/directory",
"Uses userscripts in resources/user-agent-js, or a specified full path",
PathBuf::from("resources/user-agent-js"),
|val: String| PathBuf::from(val),
)
}
fn webdriver_port() -> impl Parser<Option<u16>> {
flag_with_default_parser(
None,
@@ -532,11 +517,6 @@ struct CmdArgs {
#[bpaf(short('u'),long,argument::<String>("NCSA mosaic/1.0 (X11;SunOS 4.1.4 sun4m"))]
user_agent: Option<String>,
///
/// Uses userscripts in resources/user-agent-js, or a specified full path.
#[bpaf(external)]
userscripts: Option<PathBuf>,
///
/// Add each of the given UTF-8 encoded CSS files in the space or comma-separated
/// list as user stylesheet to apply to every page loaded.
@@ -685,7 +665,6 @@ fn parse_arguments_helper(args_without_binary: Args) -> ArgumentParsingResult {
webdriver_port: Cell::new(cmd_args.webdriver_port),
output_image_path: cmd_args.output.map(|p| p.to_string_lossy().into_owned()),
exit_after_stable_image: cmd_args.exit,
userscripts_directory: cmd_args.userscripts,
user_stylesheets: cmd_args.user_stylesheet,
experimental_preferences_enabled: cmd_args.enable_experimental_web_platform_features,
#[cfg(target_env = "ohos")]