servoshell: Add button to toggle experimental web platform features. (#39125)

This makes it easier to experiment with the impact of experimental
features when browsing around in servoshell. The toggle is global and
causes all webviews to reload with the new preference values.

Testing: Manually tested; no UI testing for servoshell.

Not enabled:
<img width="317" height="82" alt="Screenshot 2025-09-03 at 9 34 30 PM"
src="https://github.com/user-attachments/assets/ca521ad5-ce1b-434e-a0c3-ea1b75d76d53"
/>

Enabled:
<img width="320" height="82" alt="Screenshot 2025-09-03 at 9 34 36 PM"
src="https://github.com/user-attachments/assets/7b6529b5-1055-4ae0-924a-96d57e115714"
/>

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-09-03 22:53:12 -04:00 committed by GitHub
parent 912b83b58f
commit aac6aa6c70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 45 additions and 2 deletions

View file

@ -98,6 +98,7 @@ use profile_traits::mem::MemoryReportResult;
use profile_traits::{mem, time}; use profile_traits::{mem, time};
use script::{JSEngineSetup, ServiceWorkerManager}; use script::{JSEngineSetup, ServiceWorkerManager};
use servo_config::opts::Opts; use servo_config::opts::Opts;
pub use servo_config::prefs::PrefValue;
use servo_config::prefs::Preferences; use servo_config::prefs::Preferences;
use servo_config::{opts, pref, prefs}; use servo_config::{opts, pref, prefs};
use servo_delegate::DefaultServoDelegate; use servo_delegate::DefaultServoDelegate;
@ -1083,6 +1084,12 @@ impl Servo {
.send(EmbedderToConstellationMessage::WebDriverCommand(command)); .send(EmbedderToConstellationMessage::WebDriverCommand(command));
} }
} }
pub fn set_preference(&self, name: &str, value: PrefValue) {
let mut preferences = prefs::get().clone();
preferences.set_value(name, value);
prefs::set(preferences);
}
} }
fn create_embedder_channel( fn create_embedder_channel(

View file

@ -119,6 +119,7 @@ impl App {
event_loop, event_loop,
proxy, proxy,
self.initial_url.clone(), self.initial_url.clone(),
&self.servoshell_preferences,
)); ));
Rc::new(window) Rc::new(window)
}, },
@ -321,6 +322,12 @@ impl App {
focused_webview.reload(); focused_webview.reload();
} }
}, },
MinibrowserEvent::ReloadAll => {
minibrowser.update_location_dirty(false);
for (_, webview) in state.webviews() {
webview.reload();
}
},
MinibrowserEvent::NewWebView => { MinibrowserEvent::NewWebView => {
minibrowser.update_location_dirty(false); minibrowser.update_location_dirty(false);
state.create_and_focus_toplevel_webview(Url::parse("servo:newtab").unwrap()); state.create_and_focus_toplevel_webview(Url::parse("servo:newtab").unwrap());

View file

@ -22,7 +22,9 @@ use servo::base::id::WebViewId;
use servo::servo_geometry::DeviceIndependentPixel; use servo::servo_geometry::DeviceIndependentPixel;
use servo::servo_url::ServoUrl; use servo::servo_url::ServoUrl;
use servo::webrender_api::units::DevicePixel; use servo::webrender_api::units::DevicePixel;
use servo::{Image, LoadStatus, OffscreenRenderingContext, PixelFormat, RenderingContext, WebView}; use servo::{
Image, LoadStatus, OffscreenRenderingContext, PixelFormat, PrefValue, RenderingContext, WebView,
};
use winit::event::{ElementState, MouseButton, WindowEvent}; use winit::event::{ElementState, MouseButton, WindowEvent};
use winit::event_loop::ActiveEventLoop; use winit::event_loop::ActiveEventLoop;
use winit::window::Window; use winit::window::Window;
@ -33,6 +35,7 @@ use super::events_loop::EventLoopProxy;
use super::geometry::winit_position_to_euclid_point; use super::geometry::winit_position_to_euclid_point;
use super::headed_window::Window as ServoWindow; use super::headed_window::Window as ServoWindow;
use crate::desktop::window_trait::WindowPortsMethods; use crate::desktop::window_trait::WindowPortsMethods;
use crate::prefs::{EXPERIMENTAL_PREFS, ServoShellPreferences};
pub struct Minibrowser { pub struct Minibrowser {
rendering_context: Rc<OffscreenRenderingContext>, rendering_context: Rc<OffscreenRenderingContext>,
@ -55,6 +58,9 @@ pub struct Minibrowser {
/// ///
/// These need to be cached across egui draw calls. /// These need to be cached across egui draw calls.
favicon_textures: HashMap<WebViewId, (egui::TextureHandle, egui::load::SizedTexture)>, favicon_textures: HashMap<WebViewId, (egui::TextureHandle, egui::load::SizedTexture)>,
/// Whether the user has enabled experimental preferences.
experimental_prefs_enabled: bool,
} }
pub enum MinibrowserEvent { pub enum MinibrowserEvent {
@ -63,6 +69,7 @@ pub enum MinibrowserEvent {
Back, Back,
Forward, Forward,
Reload, Reload,
ReloadAll,
NewWebView, NewWebView,
CloseWebView(WebViewId), CloseWebView(WebViewId),
} }
@ -88,6 +95,7 @@ impl Minibrowser {
event_loop: &ActiveEventLoop, event_loop: &ActiveEventLoop,
event_loop_proxy: EventLoopProxy, event_loop_proxy: EventLoopProxy,
initial_url: ServoUrl, initial_url: ServoUrl,
preferences: &ServoShellPreferences,
) -> Self { ) -> Self {
let rendering_context = window.offscreen_rendering_context(); let rendering_context = window.offscreen_rendering_context();
// Adapted from https://github.com/emilk/egui/blob/9478e50d012c5138551c38cbee16b07bc1fcf283/crates/egui_glow/examples/pure_glow.rs // Adapted from https://github.com/emilk/egui/blob/9478e50d012c5138551c38cbee16b07bc1fcf283/crates/egui_glow/examples/pure_glow.rs
@ -118,6 +126,7 @@ impl Minibrowser {
load_status: LoadStatus::Complete, load_status: LoadStatus::Complete,
status_text: None, status_text: None,
favicon_textures: Default::default(), favicon_textures: Default::default(),
experimental_prefs_enabled: preferences.experimental_prefs_enabled,
} }
} }
@ -336,6 +345,19 @@ impl Minibrowser {
ui.available_size(), ui.available_size(),
egui::Layout::right_to_left(egui::Align::Center), egui::Layout::right_to_left(egui::Align::Center),
|ui| { |ui| {
let prefs_toggle = ui
.toggle_value(&mut self.experimental_prefs_enabled, "")
.on_hover_text("Enable experimental prefs");
if prefs_toggle.clicked() {
let enable = self.experimental_prefs_enabled;
for pref in EXPERIMENTAL_PREFS {
state
.servo()
.set_preference(pref, PrefValue::Bool(enable));
}
event_queue.borrow_mut().push(MinibrowserEvent::ReloadAll);
}
let location_id = egui::Id::new("location_input"); let location_id = egui::Id::new("location_input");
let location_field = ui.add_sized( let location_field = ui.add_sized(
ui.available_size(), ui.available_size(),

View file

@ -88,6 +88,9 @@ pub(crate) struct ServoShellPreferences {
/// Log also to a file /// Log also to a file
#[cfg(target_env = "ohos")] #[cfg(target_env = "ohos")]
pub log_to_file: bool, pub log_to_file: bool,
/// Whether the CLI option to enable experimental prefs was present at startup.
pub experimental_prefs_enabled: bool,
} }
impl Default for ServoShellPreferences { impl Default for ServoShellPreferences {
@ -111,6 +114,7 @@ impl Default for ServoShellPreferences {
log_filter: None, log_filter: None,
#[cfg(target_env = "ohos")] #[cfg(target_env = "ohos")]
log_to_file: false, log_to_file: false,
experimental_prefs_enabled: false,
} }
} }
} }
@ -605,7 +609,9 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
}) })
.collect(); .collect();
if opt_match.opt_present("enable-experimental-web-platform-features") { let experimental_prefs_enabled =
opt_match.opt_present("enable-experimental-web-platform-features");
if experimental_prefs_enabled {
for pref in EXPERIMENTAL_PREFS { for pref in EXPERIMENTAL_PREFS {
preferences.set_value(pref, PrefValue::Bool(true)); preferences.set_value(pref, PrefValue::Bool(true));
} }
@ -677,6 +683,7 @@ pub(crate) fn parse_command_line_arguments(args: Vec<String>) -> ArgumentParsing
log_filter, log_filter,
#[cfg(target_env = "ohos")] #[cfg(target_env = "ohos")]
log_to_file, log_to_file,
experimental_prefs_enabled,
..Default::default() ..Default::default()
}; };