Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions moli-core/src/page/settings_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,39 @@ impl Page {
.await
}

pub async fn set_navigator_overrides_async(
&mut self,
overrides: &moli_page_types::NavigatorOverrides,
) -> Result<()> {
self.dispatch_unit_page_command_async(
RendererPageCommand::SetNavigatorOverrides(overrides.clone()),
"set navigator overrides",
)
.await
}

pub fn start_set_navigator_overrides(
&self,
overrides: &moli_page_types::NavigatorOverrides,
) -> Result<PendingPageCommand> {
self.start_page_command(RendererPageCommand::SetNavigatorOverrides(
overrides.clone(),
))
}

pub fn finish_set_navigator_overrides(
&mut self,
completion: CompletedPageCommand,
) -> Result<()> {
let reply = self.finish_page_command(completion);
expect_page_reply!(
reply,
"set navigator overrides",
"a unit reply",
RendererPageReply::Unit => Ok(()),
)
}

pub fn start_set_network_offline(&self, offline: bool) -> Result<PendingPageCommand> {
self.start_page_command(RendererPageCommand::SetNetworkOffline(offline))
}
Expand Down
2 changes: 2 additions & 0 deletions moli-core/src/runtime/navigation_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ pub struct PreparedDocumentPageCommitConfiguration {
pub cpu_throttling_rate: f64,
pub emulated_media: EmulatedMediaOverrides,
pub idle_override: Option<crate::page::EmulatedIdleOverride>,
pub navigator_overrides: moli_page_types::NavigatorOverrides,
pub viewport_surface: Option<ViewportSurface>,
pub browser_resource_runtime: BrowserResourceRuntime,
pub navigator_identity: moli_browser_profile::BrowserIdentityProfile,
Expand Down Expand Up @@ -271,6 +272,7 @@ impl PreparedDocumentPage {
cpu_throttling_rate: configuration.cpu_throttling_rate,
emulated_media: configuration.emulated_media,
idle_override: configuration.idle_override,
navigator_overrides: configuration.navigator_overrides,
viewport_surface: configuration.viewport_surface,
browser_resource_runtime: configuration.browser_resource_runtime,
navigator_identity: configuration.navigator_identity,
Expand Down
2 changes: 2 additions & 0 deletions moli-page-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod inspector_identity;
mod inspector_state;
mod layout;
mod navigation_history;
mod navigator_overrides;
mod renderer_transport_memory;

use std::{
Expand Down Expand Up @@ -49,6 +50,7 @@ pub use inspector_identity::{
RendererInspectorResponseDelivery,
};
pub use layout::LayoutPolicy;
pub use navigator_overrides::{GeolocationPositionOverride, NavigatorOverrides};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DocumentNodeAttributeSnapshot {
Expand Down
24 changes: 24 additions & 0 deletions moli-page-types/src/navigator_overrides.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! Browser-owned emulation inputs consumed by native Navigator/Geolocation APIs.
//!
//! These values are state, not document-start JavaScript. Updating or clearing
//! an override must not replace Web IDL descriptors or expose a second object.

#[derive(Clone, Debug, Default, PartialEq)]
pub struct NavigatorOverrides {
/// None uses the renderer's actual network state.
pub online: Option<bool>,
pub max_touch_points: u32,
/// None means that no emulated coordinate source is available.
pub geolocation: Option<GeolocationPositionOverride>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct GeolocationPositionOverride {
pub latitude: f64,
pub longitude: f64,
pub accuracy: f64,
pub altitude: Option<f64>,
pub altitude_accuracy: Option<f64>,
pub heading: Option<f64>,
pub speed: Option<f64>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ pub(crate) struct TargetNavigationLoadInputs {
pub(crate) emulated_media: moli_core::page::EmulatedMediaOverrides,
pub(crate) viewport_surface: Option<moli_core::page::ViewportSurface>,
pub(crate) network_offline: bool,
pub(crate) navigator_overrides: moli_page_types::NavigatorOverrides,
pub(crate) bypass_service_worker: bool,
pub(crate) cache_disabled: bool,
pub(crate) blocked_url_patterns: Vec<String>,
Expand Down Expand Up @@ -336,6 +337,9 @@ impl TargetNavigationLoadInputs {
network_offline: page_state.network_policy.network_offline()
|| effective_network_conditions
.is_some_and(|conditions| !conditions.navigator_online()),
navigator_overrides: browser_context
.navigator_overrides_for_target(target_id)
.expect("resolved Page target retains its navigator state"),
bypass_service_worker: effective_policy.bypass_service_worker(),
cache_disabled: effective_policy.cache_disabled(),
blocked_url_patterns: effective_policy.blocked_url_patterns().to_vec(),
Expand Down Expand Up @@ -403,6 +407,7 @@ impl TargetNavigationLoadInputs {
emulated_media: Default::default(),
viewport_surface: None,
network_offline: false,
navigator_overrides: Default::default(),
bypass_service_worker: false,
cache_disabled: false,
blocked_url_patterns: Vec::new(),
Expand Down
11 changes: 11 additions & 0 deletions moli-protocol/src/conn/page_state/page_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ impl BrowserContext {
return Ok(false);
}
target.reset_primary_session_target_state_fields();
let navigator_overrides = self
.navigator_overrides_for_target(target_id)
.expect("disposing target retains navigator state");

let effective_headers = self.effective_extra_headers_for_target(target_id);
let target = self
Expand Down Expand Up @@ -516,6 +519,14 @@ impl BrowserContext {
anyhow::anyhow!("failed to restore page timezone: {error}")
});
}
if let Err(error) = page
.set_navigator_overrides_async(&navigator_overrides)
.await
{
first_error.get_or_insert_with(|| {
anyhow::anyhow!("failed to restore native navigator state: {error}")
});
}
if let Some(surface_script) = surface_script
&& let Err(error) = page
.run_page_surface_override_script_async(&surface_script.source)
Expand Down
Loading
Loading