Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
refactor(cdp): keep navigation engines with target owners
ldm019a59d0d6ec9
diff --git a/moli-core/src/runtime/navigation_engine.rs b/moli-core/src/runtime/navigation_engine.rsindex 5c00e6085..7eade1a3d 100644--- a/moli-core/src/runtime/navigation_engine.rs+++ b/moli-core/src/runtime/navigation_engine.rs@@ -640,22 +640,6 @@ impl NavigationEngine {})}- /// Creates an isolated navigation-attempt engine for an existing target.- ///- /// The attempt owns mutable Page policy until commit, while retaining the- /// stable target's renderer memory-cache capability across navigation.- pub fn new_for_target_navigation_with_shared_renderer_owner(- config: NavigationRuntimeConfig,- renderer_owner_source: &Self,- ) -> Result<Self> {- let mut engine =- Self::new_with_runtime_config_and_shared_renderer_owner(config, renderer_owner_source)?;- engine- .page_network_policy- .adopt_memory_cache_partition_from(&renderer_owner_source.page_network_policy);- Ok(engine)- }-pub fn new_with_page_vm_document_isolate_for_diagnostics() -> Self {Self::new()}@@ -2625,31 +2609,6 @@ mod tests {);}- #[test]- fn target_navigation_attempt_keeps_page_memory_cache_capability() {- let mut resident = NavigationEngine::new();- resident.set_cache_disabled(true);- let resident_loader = resident- .resource_request_client()- .expect("resident target request client");- let attempt = NavigationEngine::new_for_target_navigation_with_shared_renderer_owner(- resident.runtime_config(),- &resident,- )- .expect("target navigation attempt should share a live renderer owner");- let attempt_loader = attempt- .resource_request_client()- .expect("navigation attempt request client");-- assert!(resident_loader.shares_resource_runtime_with(&attempt_loader));- assert!(!resident_loader.shares_page_network_policy_with(&attempt_loader));- assert!(resident_loader.shares_memory_cache_partition_with(&attempt_loader));- assert!(- !attempt_loader.page_network_policy().cache_disabled(),- "a navigation attempt must receive policy from captured load inputs, not stale engine state"- );- }-#[test]fn navigation_engine_clone_keeps_the_standalone_owner_live_after_source_drop() {let engine = NavigationEngine::new();diff --git a/moli-protocol/src/conn.rs b/moli-protocol/src/conn.rsindex 398f3d304..e10e84eaf 100644--- a/moli-protocol/src/conn.rs+++ b/moli-protocol/src/conn.rs@@ -560,13 +560,12 @@ pub(crate) use state::{DevToolsEmulationSessionState, DevToolsLogViolationThreshold, DocumentNavigationToken,DuplicatePendingRendererCommand, EffectiveTargetEmulationState,EffectiveTargetEmulationStateDelta, EmulatedNetworkConditions, EmulatedViewportSurface,- InspectorCommandDispatch, NETWORK_ERROR_PAGE_URL, NavigationEngineHandoff,- NavigationResultProjection, NavigationSourceDocumentSecurityContext,- NetworkErrorPageNavigation, PageScreencastConfig, PageScreencastFormat,- PendingBidiChannelListener, PendingInspectorAwait, PendingRendererCommandKey,- PerformanceTimeDomain, PreparedRendererCallDispatch, ProfilerAction, ProfilerInspectorCommand,- RendererCommandCorrelation, RendererCommandDescriptor, RendererCommandReplay,- RendererDocumentLifecycleObservation, RendererDocumentLifecycleObserver,+ InspectorCommandDispatch, NETWORK_ERROR_PAGE_URL, NavigationResultProjection,+ NavigationSourceDocumentSecurityContext, NetworkErrorPageNavigation, PageScreencastConfig,+ PageScreencastFormat, PendingBidiChannelListener, PendingInspectorAwait,+ PendingRendererCommandKey, PerformanceTimeDomain, PreparedRendererCallDispatch, ProfilerAction,+ ProfilerInspectorCommand, RendererCommandCorrelation, RendererCommandDescriptor,+ RendererCommandReplay, RendererDocumentLifecycleObservation, RendererDocumentLifecycleObserver,RendererMainDocumentCommitSeed, RendererPageResidenceIdentity,ServiceWorkerRuntimeExceptionSnapshot, ServiceWorkerTargetState, SharedWorkerTargetState,SiteDataClearOptions, TargetIdentityState, TargetInitialEmptyDocumentCreator, TargetOwnerState,@@ -2553,13 +2552,11 @@ impl CdpConnection {ready_to_enqueue_ms = completion.ready_elapsed_ms(),);}- // Always complete the materialized navigation so the client receives- // a terminal Page.navigate response (success or abort-error) for the- // outstanding command id. The completion helper is responsible for the- // navigate_id-gated abort emission; the only thing we must avoid here- // is letting the stale background engine displace the live one.- let is_current = completion.is_current_for_connection(self);- let completion = completion.materialize_with_engine_replacement(self, is_current);+ // Always materialize the navigation so the client receives a terminal+ // Page.navigate response (success or abort-error) for the outstanding+ // command id. The target retains its NavigationEngine independently of+ // this completion, including when the completion is stale.+ let completion = completion.materialize(self);if let Some(started) = timing_started {tracing::info!(target: "moli_cdp_nav_timing",@@ -2583,65 +2580,6 @@ impl CdpConnection {}}- fn install_page_navigation_engine(- &mut self,- browser_context_id: &str,- target_id: &str,- engine: NavigationEngine,- ) -> Result<(), String> {- let owner_access = self- .browser_context_by_id(browser_context_id)- .ok_or_else(|| {- format!(- "cannot install navigation engine for missing BrowserContext `{browser_context_id}`"- )- })?- .renderer_runtime_owner_access();- if !engine- .browser_context_runtime()- .shares_state_with(&owner_access.runtime())- {- return Err(format!(- "navigation engine renderer context does not match BrowserContext `{browser_context_id}`"- ));- }- self.apply_scheduler_senders_to_navigation_engine(&engine);- let replaced = self- .browser_context_by_id_mut(browser_context_id)- .and_then(|context| context.page_target_mut(target_id))- .ok_or_else(|| {- format!("cannot install navigation engine for missing Page target `{target_id}`")- })?- .replace_navigation_engine(engine);- drop(replaced);- owner_access.reap_retired_resource_runtimes();- Ok(())- }-- pub(crate) fn adopt_loaded_navigation_engine_for_owner(- &mut self,- owner: &CommandOwnerScope,- engine: NavigationEngine,- ) {- let Some((browser_context_id, Some(target_id))) =- self.target_owner_identity_for_owner(owner)- else {- self.replace_standalone_navigation_engine(engine);- return;- };- self.install_page_navigation_engine(&browser_context_id, &target_id, engine)- .expect("page owner must install its exact PageTargetHost engine");- }-- pub(crate) fn adopt_loaded_navigation_engine_for_page_owner(- &mut self,- owner: &InitialDocumentPageOwner,- engine: NavigationEngine,- ) {- self.install_page_navigation_engine(&owner.browser_context_id, &owner.target_id, engine)- .expect("page owner must install its exact PageTargetHost engine");- }-pub(crate) fn enqueue_deferred_main_document_load_completion(&mut self,admission: crate::domains::activity::DeferredMainDocumentLoadCompletionAdmission,@@ -2890,12 +2828,11 @@ impl CdpConnection {);}let is_current = completion.is_current_for_connection(self);- let (token, state, navigation, engine_handoff) = completion.into_parts();+ let (token, state, navigation) = completion.into_parts();if !is_current {crate::domains::page::push_superseded_navigation_result(out, &state);return;}- let navigation_owner = state.owner.clone();crate::domains::page::complete_materialized_navigation_into_buffer_async(self,out,@@ -2905,9 +2842,6 @@ impl CdpConnection {command_context,).await;- if let Some(engine) = engine_handoff.into_replacement() {- self.adopt_loaded_navigation_engine_for_owner(&navigation_owner, engine);- }if let Some(started) = timing_started {tracing::info!(target: "moli_cdp_nav_timing",diff --git a/moli-protocol/src/conn/fetch_support.rs b/moli-protocol/src/conn/fetch_support.rsindex 6736a4c47..b2f7c4143 100644--- a/moli-protocol/src/conn/fetch_support.rs+++ b/moli-protocol/src/conn/fetch_support.rs@@ -1563,8 +1563,7 @@ impl DocumentBodySource {..} => {if !has_response_override && let Some(prepared_document) = prepared_document {- let (engine, navigation) = prepared_document.resume_streaming(response, None);- return Ok(navigation.with_navigation_engine_replacement(engine));+ return Ok(prepared_document.resume_streaming(response, None));}conn.build_navigation_from_streaming_raw_response_with_response_override_for_navigation_async(navigation,diff --git a/moli-protocol/src/conn/page_state/fetch_state.rs b/moli-protocol/src/conn/page_state/fetch_state.rsindex b219a9a6e..2a5597897 100644--- a/moli-protocol/src/conn/page_state/fetch_state.rs+++ b/moli-protocol/src/conn/page_state/fetch_state.rs@@ -65,8 +65,7 @@ impl BrowserContext {host.set_base_cache_disabled(self.global_cache_disabled);if let Some(config) = self.page_navigation_runtime_config.clone() {let engine = self.new_page_navigation_engine(config);- let replaced = host.replace_navigation_engine(engine);- debug_assert!(replaced.is_none());+ host.install_navigation_engine(engine);}self.page_targets.insert(host)}diff --git a/moli-protocol/src/conn/resource_runtime_support.rs b/moli-protocol/src/conn/resource_runtime_support.rsindex 11c3175be..6be1c287c 100644--- a/moli-protocol/src/conn/resource_runtime_support.rs+++ b/moli-protocol/src/conn/resource_runtime_support.rs@@ -57,7 +57,7 @@ impl CdpConnection {.ok_or_else(|| "resource request client unavailable".to_owned())}- fn configured_navigation_engine_for_load_inputs_mut(+ pub(super) fn configured_navigation_engine_for_load_inputs_mut(&mut self,load_inputs: &TargetNavigationLoadInputs,) -> Option<&mut moli_core::runtime::NavigationEngine> {diff --git a/moli-protocol/src/conn/runtime_load.rs b/moli-protocol/src/conn/runtime_load.rsindex 5750a7b96..cdc72beb7 100644--- a/moli-protocol/src/conn/runtime_load.rs+++ b/moli-protocol/src/conn/runtime_load.rs@@ -176,7 +176,6 @@ enum PendingInitialDocumentPageBuildKind {owner: InitialDocumentPageOwner,load_inputs: Box<TargetNavigationLoadInputs>,override_mode: NavigationLoadInputOverrideMode,- engine: Box<Option<NavigationEngine>>,pending: moli_core::runtime::PendingBuiltDocumentPage,},Join {@@ -189,7 +188,6 @@ pub(crate) enum CompletedInitialDocumentPageBuild {owner: InitialDocumentPageOwner,load_inputs: Box<TargetNavigationLoadInputs>,override_mode: NavigationLoadInputOverrideMode,- engine: Box<Option<NavigationEngine>>,built: Box<moli_core::runtime::BuiltDocumentPage>,},Joined,@@ -248,7 +246,6 @@ impl PendingInitialDocumentPageBuild {owner,load_inputs,override_mode,- engine,pending,} => {let built = match pending.await_ready().await {@@ -264,7 +261,6 @@ impl PendingInitialDocumentPageBuild {owner,load_inputs,override_mode,- engine,built: Box::new(built),})}@@ -305,7 +301,6 @@ pub struct ResponseCommitReady {response_status: u16,response_headers: Vec<(String, String)>,response_from_cache: bool,- navigation_engine_handoff: NavigationEngineHandoff,timing_started: Option<std::time::Instant>,main_document_commit: Option<Arc<RendererMainDocumentCommit>>,network_error_page: Option<NetworkErrorPageNavigation>,@@ -399,11 +394,6 @@ impl ResponseCommitReady {.issue_commit_permit()}- pub(crate) fn with_navigation_engine_replacement(mut self, engine: NavigationEngine) -> Self {- self.navigation_engine_handoff = NavigationEngineHandoff::replacement(engine);- self- }-pub(crate) async fn commit(mut self,permit: PreparedDocumentPageCommitPermit,@@ -492,10 +482,6 @@ impl ResponseCommitReady {renderer_output_predecessor: diagnostics.renderer_output_predecessor,main_document_commit: self.main_document_commit.take(),document_progress_transfer,- navigation_engine_handoff: std::mem::replace(- &mut self.navigation_engine_handoff,- NavigationEngineHandoff::retained_by_owner(),- ),network_error_page: self.network_error_page.take(),})}@@ -524,7 +510,6 @@ pub struct PausedResponsePreparedDocument {response_from_cache: bool,negotiated_http_version: Option<moli_fetch::NegotiatedHttpVersion>,network_observation_journal: NetworkObservationJournal,- engine: NavigationEngine,timing_started: Option<std::time::Instant>,main_document_commit: Option<Arc<RendererMainDocumentCommit>>,}@@ -555,7 +540,7 @@ impl PausedResponsePreparedDocument {self,response: StreamingRawResponse,body_completion_sink: Option<BackgroundNavigationBodyCompletionSink>,- ) -> (NavigationEngine, NavigationLoadOutcome) {+ ) -> NavigationLoadOutcome {let network_extra_info_available = !self.network_observation_journal.is_empty();self.body_progress_source.emit_response_metadata(&self.request_method,@@ -591,15 +576,11 @@ impl PausedResponsePreparedDocument {response_status: self.response_status,response_headers: self.response_headers,response_from_cache: self.response_from_cache,- navigation_engine_handoff: NavigationEngineHandoff::retained_by_owner(),timing_started: self.timing_started,main_document_commit: self.main_document_commit,network_error_page: None,};- (- self.engine,- NavigationLoadOutcome::response_commit_ready(ready),- )+ NavigationLoadOutcome::response_commit_ready(ready)}}@@ -707,8 +688,9 @@ pub(crate) struct BackgroundNavigationLoadJob {body_progress_source: MainDocumentBodyProgressSource,/// Browser-context transport/cache state shared with the resident engine.///- /// The detached job must not retain a source Page's request-policy view;- /// its own NavigationEngine supplies the target Page policy.+ /// The detached job's NavigationEngine handle shares the resident target's+ /// Page policy while retaining this exact browser-resource runtime for the+ /// captured navigation.shared_resource_runtime: Option<moli_core::network::BrowserResourceRuntime>,}@@ -831,11 +813,7 @@ impl BackgroundNavigationLoadJob {pub(crate) async fn run(mut self,body_completion_sink: Option<BackgroundNavigationBodyCompletionSink>,- ) -> (- NavigationEngine,- Result<NavigationLoadOutcome, String>,- bool,- ) {+ ) -> (Result<NavigationLoadOutcome, String>, bool) {let timing_started = moli_trace::cdp_nav_timing_enabled().then(std::time::Instant::now);let timing_url = self.raw_url.clone();let mut engine = self.engine;@@ -843,7 +821,7 @@ impl BackgroundNavigationLoadJob {if let Some(resource_runtime) = self.shared_resource_runtime.take()&& let Err(error) = engine.adopt_registered_resource_runtime(resource_runtime){- return (engine, Err(error.to_string()), false);+ return (Err(error.to_string()), false);}let mut early_result_sent = false;let navigation = async {@@ -993,7 +971,7 @@ impl BackgroundNavigationLoadJob {elapsed_ms = started.elapsed().as_millis(),);}- (engine, navigation, early_result_sent)+ (navigation, early_result_sent)}}@@ -1001,14 +979,14 @@ impl BackgroundStreamingResponseNavigationLoadJob {pub(crate) async fn run(mut self,body_completion_sink: Option<BackgroundNavigationBodyCompletionSink>,- ) -> (NavigationEngine, Result<NavigationLoadOutcome, String>) {+ ) -> Result<NavigationLoadOutcome, String> {let mut engine = self.engine;if let Some(resource_runtime) = self.shared_resource_runtime.take()&& let Err(error) = engine.adopt_registered_resource_runtime(resource_runtime){- return (engine, Err(error.to_string()));+ return Err(error.to_string());}- let navigation = build_navigation_from_streaming_raw_response_with_engine_async(+ build_navigation_from_streaming_raw_response_with_engine_async(&mut engine,self.page_reservation,&self.load_inputs,@@ -1025,8 +1003,7 @@ impl BackgroundStreamingResponseNavigationLoadJob {CommittedDocumentResourceSource::Synthetic,RendererReplyBoundary::DocumentCommit,)- .await;- (engine, navigation)+ .await}}@@ -1440,7 +1417,6 @@ async fn build_navigation_from_streaming_raw_response_with_engine_async(response_status,response_headers,response_from_cache,- navigation_engine_handoff: NavigationEngineHandoff::retained_by_owner(),timing_started: timing_enabled.then_some(timing_started),main_document_commit,network_error_page: None,@@ -1533,7 +1509,6 @@ async fn build_navigation_from_streaming_raw_response_with_engine_async(response_status,response_headers,response_from_cache,- navigation_engine_handoff: NavigationEngineHandoff::retained_by_owner(),timing_started: timing_enabled.then_some(timing_started),main_document_commit,network_error_page: None,@@ -1679,7 +1654,7 @@ impl CdpConnection {);let shared_resource_runtime =self.shared_resource_runtime_for_navigation_load_inputs(&load_inputs);- let mut engine = self.background_navigation_engine_for_load_inputs(&load_inputs);+ let mut engine = self.navigation_engine_handle_for_load_inputs(&load_inputs);if let Some(resource_runtime) = shared_resource_runtime {engine.adopt_registered_resource_runtime(resource_runtime)@@ -1759,7 +1734,6 @@ impl CdpConnection {response_from_cache,negotiated_http_version,network_observation_journal: network_observation_journal.clone(),- engine,timing_started,main_document_commit,}))@@ -1918,7 +1892,7 @@ impl CdpConnection {.unwrap_or_else(|| Url::parse("about:blank").expect("about:blank should be valid"));let (fetch_subresource_interception_enabled, fetch_subresource_interception_resource_type) =load_inputs.fetch_subresource_interception;- let mut engine = self.background_navigation_engine_for_load_inputs(&load_inputs);+ let mut engine = self.navigation_engine_handle_for_load_inputs(&load_inputs);let page_storage = load_inputs.page_storage_handles();let top_level_storage_key =self.runtime_session_owner_initial_empty_document_storage_key_for_owner(owner);@@ -2004,7 +1978,6 @@ impl CdpConnection {owner: page_owner,load_inputs: Box::new(load_inputs),override_mode: NavigationLoadInputOverrideMode::FreshlyBuiltPage,- engine: Box::new(Some(engine)),pending,},}))@@ -2142,14 +2115,12 @@ impl CdpConnection {owner,load_inputs,override_mode,- engine,built,} = completedelse {return Ok(LoadedPageCreationDiagnosticsParts::default());};let load_inputs = *load_inputs;- let engine = *engine;let built = *built;let diagnostics = loaded_page_creation_diagnostics_parts(built.page_creation_diagnostics);let page_creation_artifacts = built.page_creation_artifacts;@@ -2174,9 +2145,6 @@ impl CdpConnection {self.complete_stale_initial_document_page_build_for_page_owner(&owner);return Ok(LoadedPageCreationDiagnosticsParts::default());}- if let Some(engine) = engine {- self.adopt_loaded_navigation_engine_for_page_owner(&owner, engine);- }self.complete_initial_document_page_build_for_page_owner(&owner);Ok(diagnostics)}@@ -2363,7 +2331,7 @@ impl CdpConnection {return navigation;}} else {- let mut inline_engine = self.background_navigation_engine_for_load_inputs(&load_inputs);+ let mut inline_engine = self.navigation_engine_handle_for_load_inputs(&load_inputs);let page_reservation =self.reserve_renderer_page_for_owner(owner, &load_inputs, &inline_engine);if let Some(navigation) = self@@ -2378,9 +2346,7 @@ impl CdpConnection {).await{- return navigation.map(|navigation| {- navigation.with_navigation_engine_replacement(inline_engine)- });+ return navigation;}if let Some(navigation) = load_data_url_navigation_with_engine_async(&mut inline_engine,@@ -2393,9 +2359,7 @@ impl CdpConnection {).await{- return navigation.map(|navigation| {- navigation.with_navigation_engine_replacement(inline_engine)- });+ return navigation;}}@@ -2439,12 +2403,12 @@ impl CdpConnection {) -> Option<BackgroundNavigationLoadJob> {let cancellation = self.document_navigation_cancellation_handle(token)?;let load_inputs = self.navigation_load_inputs_for_navigation(navigation);- // Ensure the connection's resident browser resource runtime exists,- // then share only that transport/cache owner with the background job.- // Page policy remains owned by the job's NavigationEngine.+ // Ensure the target's resident browser resource runtime exists before+ // cloning its engine handle. The job shares the target Page policy and+ // retains this exact transport/cache owner for the captured navigation.let shared_resource_runtime =self.shared_resource_runtime_for_navigation_load_inputs(&load_inputs);- let engine = self.background_navigation_engine_for_load_inputs(&load_inputs);+ let engine = self.navigation_engine_handle_for_load_inputs(&load_inputs);let page_reservation =self.reserve_renderer_page_for_owner(&navigation.owner, &load_inputs, &engine);Some(BackgroundNavigationLoadJob {@@ -2491,7 +2455,7 @@ impl CdpConnection {let load_inputs = self.navigation_load_inputs_for_navigation(navigation);let shared_resource_runtime =self.shared_resource_runtime_for_navigation_load_inputs(&load_inputs);- let engine = self.background_navigation_engine_for_load_inputs(&load_inputs);+ let engine = self.navigation_engine_handle_for_load_inputs(&load_inputs);let page_reservation =self.reserve_renderer_page_for_owner(&navigation.owner, &load_inputs, &engine);BackgroundStreamingResponseNavigationLoadJob {@@ -2560,38 +2524,20 @@ impl CdpConnection {}}- pub(super) fn background_navigation_engine_for_load_inputs(- &self,+ /// Returns a task-local handle to the NavigationEngine retained by the+ /// target owner. `NavigationEngine::clone` shares the target's Page policy+ /// and renderer owner, so a background load never has to return or replace+ /// the resident engine when it completes.+ pub(super) fn navigation_engine_handle_for_load_inputs(+ &mut self,load_inputs: &TargetNavigationLoadInputs,) -> NavigationEngine {- let mut engine =- if let Some(source) = self.page_navigation_engine_for_load_inputs(load_inputs) {- NavigationEngine::new_for_target_navigation_with_shared_renderer_owner(- self.navigation_runtime_config_for_load_inputs(load_inputs),- source,- )- .expect("target Page renderer owner must be live")- } else {- NavigationEngine::new_with_runtime_config_and_browser_context_access(- self.navigation_runtime_config_for_load_inputs(load_inputs),- load_inputs.renderer_runtime.clone(),- )- .expect("navigation load BrowserContext owner must be live")- };- self.apply_fetch_overrides_to_background_navigation_engine(&mut engine, load_inputs);- if !self.page_resource_runtime_matches_navigation_load_inputs(load_inputs) {- // Sharing the renderer owner must not implicitly share a transport- // runtime that was rejected above for a different target policy.- // The next request rebuilds from this engine's effective fetch- // configuration and the target's storage partition.- engine.reset_resource_runtime_without_loaded_page();- }- engine.set_bypass_service_worker(load_inputs.bypass_service_worker);- engine.set_cache_disabled(load_inputs.cache_disabled);- // The engine may publish lifecycle or resource activity before the- // DCL-bound navigation result is adopted into a target slot. Bind its- // scheduler sender at construction time so that early tail work queues- // a wake instead of disappearing in the handoff window.+ let engine = self+ .configured_navigation_engine_for_load_inputs_mut(load_inputs)+ .expect("navigation load target must retain its resident NavigationEngine")+ .clone();+ // The handle may publish lifecycle or resource activity before the+ // DCL-bound navigation result is committed into a target slot.self.apply_scheduler_senders_to_navigation_engine(&engine);engine}@@ -2606,46 +2552,6 @@ impl CdpConnection {.page_navigation_engine(target_id)}- fn navigation_runtime_config_for_load_inputs(- &self,- load_inputs: &TargetNavigationLoadInputs,- ) -> moli_core::runtime::NavigationRuntimeConfig {- let mut config = self.standalone_navigation_engine.runtime_config();- *config.fetch_config_mut() = self.fetch_config_for_load_inputs(load_inputs);- config- }-- fn apply_fetch_overrides_to_background_navigation_engine(- &self,- engine: &mut NavigationEngine,- load_inputs: &TargetNavigationLoadInputs,- ) {- engine.set_browser_identity_override(- load_inputs- .browser_identity_override- .clone()- .or_else(|| self.global_browser_identity_override.clone())- .unwrap_or_else(|| self.base_browser_identity.clone()),- );- engine.set_http_proxy_override(- load_inputs- .http_proxy_override- .clone()- .or_else(|| self.base_http_proxy.clone()),- );- engine.set_http_no_proxy_override(- load_inputs- .http_no_proxy_override- .clone()- .or_else(|| self.base_http_no_proxy.clone()),- );- engine.set_tls_verify_host(- load_inputs- .tls_verify_host_override- .unwrap_or(self.base_tls_verify_host),- );- }-fn shared_resource_runtime_for_navigation_load_inputs(&mut self,load_inputs: &TargetNavigationLoadInputs,@@ -2722,18 +2628,7 @@ impl CdpConnection {}pub async fn load_page_via_runtime_async(&mut self, raw_url: &str) -> Result<Page, String> {- let mut navigation = self.load_navigation_via_runtime_async(raw_url).await?;- if let Some(engine) = navigation.take_navigation_engine_replacement() {- let page_owner = self.browser_context.as_ref().and_then(|context| {- Some((context.id.clone(), context.active_target_id()?.to_owned()))- });- if let Some((browser_context_id, target_id)) = page_owner {- self.install_page_navigation_engine(&browser_context_id, &target_id, engine)- .expect("loaded page must retain its exact PageTargetHost engine");- } else {- self.replace_standalone_navigation_engine(engine);- }- }+ let navigation = self.load_navigation_via_runtime_async(raw_url).await?;Ok(navigation.page)}@@ -3071,7 +2966,6 @@ impl CdpConnection {false,network_progress,),- navigation_engine_handoff: NavigationEngineHandoff::retained_by_owner(),network_error_page: None,})}@@ -3367,7 +3261,6 @@ impl CdpConnection {false,network_progress,),- navigation_engine_handoff: NavigationEngineHandoff::retained_by_owner(),network_error_page: None,})}@@ -3544,7 +3437,7 @@ impl CdpConnection {.map(NavigationLoadOutcome::response_commit_ready);}- let mut engine = self.background_navigation_engine_for_load_inputs(load_inputs);+ let mut engine = self.navigation_engine_handle_for_load_inputs(load_inputs);let page_reservation = self.reserve_renderer_page_for_owner(owner, load_inputs, &engine);let navigation = prepare_navigation_from_captured_raw_response_with_engine_async(&mut engine,@@ -3562,9 +3455,7 @@ impl CdpConnection {RendererReplyBoundary::Stage,).await?;- Ok(NavigationLoadOutcome::response_commit_ready(- navigation.with_navigation_engine_replacement(engine),- ))+ Ok(NavigationLoadOutcome::response_commit_ready(navigation))}pub async fn build_navigation_from_streaming_raw_response_async(@@ -3695,7 +3586,7 @@ impl CdpConnection {.await;}- let mut engine = self.background_navigation_engine_for_load_inputs(load_inputs);+ let mut engine = self.navigation_engine_handle_for_load_inputs(load_inputs);let page_reservation = self.reserve_renderer_page_for_owner(owner, load_inputs, &engine);let navigation = build_navigation_from_streaming_raw_response_with_engine_async(&mut engine,@@ -3715,7 +3606,7 @@ impl CdpConnection {RendererReplyBoundary::Stage,).await?;- Ok(navigation.with_navigation_engine_replacement(engine))+ Ok(navigation)}pub(crate) async fn collect_navigation_streaming_raw_response_async(@@ -3984,7 +3875,6 @@ async fn prepare_captured_document_response_with_engine_async(response_status,response_headers,response_from_cache,- navigation_engine_handoff: NavigationEngineHandoff::retained_by_owner(),timing_started: None,main_document_commit,network_error_page,diff --git a/moli-protocol/src/conn/state/browser_context.rs b/moli-protocol/src/conn/state/browser_context.rsindex 106c5a95a..d7d3fe77d 100644--- a/moli-protocol/src/conn/state/browser_context.rs+++ b/moli-protocol/src/conn/state/browser_context.rs@@ -577,8 +577,7 @@ impl BrowserContext {if let Some(sender) = sender.clone() {engine.set_renderer_output_transport_sender(sender);}- let replaced = host.replace_navigation_engine(engine);- debug_assert!(replaced.is_none());+ host.install_navigation_engine(engine);}}diff --git a/moli-protocol/src/conn/state/mod.rs b/moli-protocol/src/conn/state/mod.rsindex 993780df1..3f3ebe295 100644--- a/moli-protocol/src/conn/state/mod.rs+++ b/moli-protocol/src/conn/state/mod.rs@@ -138,7 +138,6 @@ pub use navigation_outcome::{NavigationRequestLoadPolicy, TargetInfo,};pub(crate) use navigation_outcome::{- NETWORK_ERROR_PAGE_URL, NavigationEngineHandoff, NavigationResultProjection,- NavigationSourceDocumentSecurityContext, NetworkErrorPageNavigation,- RendererMainDocumentCommitSeed,+ NETWORK_ERROR_PAGE_URL, NavigationResultProjection, NavigationSourceDocumentSecurityContext,+ NetworkErrorPageNavigation, RendererMainDocumentCommitSeed,};diff --git a/moli-protocol/src/conn/state/navigation_outcome.rs b/moli-protocol/src/conn/state/navigation_outcome.rsindex 05265997a..8ad93c36e 100644--- a/moli-protocol/src/conn/state/navigation_outcome.rs+++ b/moli-protocol/src/conn/state/navigation_outcome.rs@@ -2,7 +2,6 @@ use moli_core::page::{Page, RendererMainDocumentCommit, RendererPageCreationArtifacts,RendererPendingDownloadActivation, RendererRuntimeRealmInfo,};-use moli_core::runtime::NavigationEngine;use moli_fetch::StreamingRawResponse;use serde::Serialize;use serde_json::Value;@@ -19,35 +18,6 @@ use super::browser_context::BrowserContext;pub(crate) const NETWORK_ERROR_PAGE_URL: &str = "chrome-error://chromewebdata/";-/// What must happen to the navigation engine after a completed load is-/// committed.-///-/// Foreground loads borrow the engine already installed on their target.-/// Background loads own a temporary engine and must return it to that exact-/// target after commit. Keeping this distinction explicit prevents an omitted-/// replacement handoff from silently looking like a valid background load.-#[derive(Debug)]-pub(crate) struct NavigationEngineHandoff(Option<NavigationEngine>);--impl NavigationEngineHandoff {- pub(crate) fn retained_by_owner() -> Self {- Self(None)- }-- pub(crate) fn replacement(engine: NavigationEngine) -> Self {- Self(Some(engine))- }-- pub(crate) fn into_replacement(self) -> Option<NavigationEngine> {- self.0- }-- #[cfg(test)]- pub(crate) fn replacement_ref(&self) -> Option<&NavigationEngine> {- self.0.as_ref()- }-}-#[derive(Clone, Debug)]pub(crate) struct NetworkErrorPageNavigation {error_text: String,@@ -223,29 +193,10 @@ pub struct LoadedNavigation {pub renderer_output_predecessor: Option<moli_core::RendererOutputFence>,pub(crate) main_document_commit: Option<Arc<RendererMainDocumentCommit>>,pub(crate) document_progress_transfer: CompletedDocumentProgressTransfer,- pub(crate) navigation_engine_handoff: NavigationEngineHandoff,pub(crate) network_error_page: Option<NetworkErrorPageNavigation>,}impl LoadedNavigation {- pub(crate) fn with_navigation_engine_replacement(mut self, engine: NavigationEngine) -> Self {- self.navigation_engine_handoff = NavigationEngineHandoff::replacement(engine);- self- }-- pub(crate) fn take_navigation_engine_replacement(&mut self) -> Option<NavigationEngine> {- std::mem::replace(- &mut self.navigation_engine_handoff,- NavigationEngineHandoff::retained_by_owner(),- )- .into_replacement()- }-- #[cfg(test)]- pub(crate) fn navigation_engine_replacement(&self) -> Option<&NavigationEngine> {- self.navigation_engine_handoff.replacement_ref()- }-#[cfg(test)]pub(crate) fn response_body(&self) -> String {self.document_progress_transfer@@ -283,10 +234,6 @@ impl NavigationLoadOutcome {Self::ResponseCommitReady(Box::new(navigation))}- pub(crate) fn loaded(navigation: LoadedNavigation) -> Self {- Self::Loaded(Box::new(navigation))- }-pub(crate) fn download(navigation: DownloadNavigation) -> Self {Self::Download(Box::new(navigation))}@@ -294,19 +241,6 @@ impl NavigationLoadOutcome {pub(crate) fn network_failure(error_text: String) -> Self {Self::NetworkFailure(error_text)}-- pub(crate) fn with_navigation_engine_replacement(self, engine: NavigationEngine) -> Self {- match self {- Self::ResponseCommitReady(navigation) => {- Self::response_commit_ready(navigation.with_navigation_engine_replacement(engine))- }- Self::Loaded(navigation) => {- Self::loaded(navigation.with_navigation_engine_replacement(engine))- }- Self::Download(navigation) => Self::Download(navigation),- Self::NetworkFailure(error_text) => Self::NetworkFailure(error_text),- }- }}#[derive(Debug, Clone)]diff --git a/moli-protocol/src/conn/state/page_target_host.rs b/moli-protocol/src/conn/state/page_target_host.rsindex c13f85ef7..f6ce560d3 100644--- a/moli-protocol/src/conn/state/page_target_host.rs+++ b/moli-protocol/src/conn/state/page_target_host.rs@@ -166,14 +166,15 @@ impl PageTargetHost {self.navigation_engine.as_mut()}- pub(crate) fn replace_navigation_engine(- &mut self,- mut engine: NavigationEngine,- ) -> Option<NavigationEngine> {+ pub(crate) fn install_navigation_engine(&mut self, mut engine: NavigationEngine) {+ assert!(+ self.navigation_engine.is_none(),+ "PageTargetHost must retain its first installed NavigationEngine"+ );let policy = self.effective_policy();engine.set_bypass_service_worker(policy.bypass_service_worker());engine.set_cache_disabled(policy.cache_disabled());- self.navigation_engine.replace(engine)+ self.navigation_engine = Some(engine);}pub(crate) fn set_base_cache_disabled(&mut self, disabled: bool) {diff --git a/moli-protocol/src/conn/tests/mod.rs b/moli-protocol/src/conn/tests/mod.rsindex 494ebca8e..28bf217a1 100644--- a/moli-protocol/src/conn/tests/mod.rs+++ b/moli-protocol/src/conn/tests/mod.rs@@ -1207,41 +1207,6 @@ fn page_navigation_engines_remain_target_local_across_selection() {);}-#[test]-fn page_target_host_rejects_a_foreign_browser_context_engine() {- let mut conn = CdpConnection::new();- let mut context = BrowserContext::new("BID-retain-route".to_owned());- context.set_active_target_id("TID-retain-route");- conn.insert_browser_context(context);- let original_owner = conn- .active_navigation_engine()- .renderer_owner_id_for_diagnostics();- let foreign_context = BrowserContext::new("BID-retain-route-foreign".to_owned());- let foreign_engine = NavigationEngine::new_with_fetch_config_and_browser_context_access(- FetchConfig::default(),- foreign_context.renderer_runtime_owner_access(),- conn.standalone_navigation_engine- .ensure()- .optional_resource_fetch_mask(),- conn.standalone_navigation_engine- .ensure()- .subframe_loading_enabled(),- )- .expect("foreign context owner should be live during the regression");-- let error = conn- .install_page_navigation_engine("BID-retain-route", "TID-retain-route", foreign_engine)- .expect_err("a PageTargetHost must reject an engine from another BrowserContext");-- assert!(error.contains("does not match BrowserContext `BID-retain-route`"));- assert_eq!(- conn.active_navigation_engine()- .renderer_owner_id_for_diagnostics(),- original_owner,- "rejecting a foreign engine must preserve the host's resident engine"- );-}-#[tokio::test]async fn memory_diagnostics_splits_pending_inspector_await_counts_by_target_owner() {let mut conn = CdpConnection::new();diff --git a/moli-protocol/src/conn/tests/resource_runtime.rs b/moli-protocol/src/conn/tests/resource_runtime.rsindex 445650b65..9d749772a 100644--- a/moli-protocol/src/conn/tests/resource_runtime.rs+++ b/moli-protocol/src/conn/tests/resource_runtime.rs@@ -78,7 +78,7 @@ async fn commit_navigation_outcome_for_session_test(}#[tokio::test]-async fn buffered_navigation_for_inactive_session_carries_its_target_engine() {+async fn buffered_navigation_for_inactive_session_retains_its_target_engine() {let mut conn = CdpConnection::new();let ambient_context = conn.new_browser_context("BID-ambient".to_owned());conn.insert_browser_context(ambient_context);@@ -95,11 +95,16 @@ async fn buffered_navigation_for_inactive_session_carries_its_target_engine() {.start_document_navigation_for_active_target("LOADER-target".to_owned()).expect("target should accept its synthetic navigation");conn.push_inactive_browser_context_fixture_for_test(target_context);+ let owner = crate::conn::CommandOwnerScope::for_session("SID-target");+ let load_inputs = conn.navigation_load_inputs_for_owner(&owner);+ let resident_client = conn+ .ensure_resource_request_client_for_navigation_load_inputs(&load_inputs)+ .expect("inactive target must initialize its resident navigation engine");let requested_url = Url::parse("https://target.example/fulfilled").unwrap();let navigation = NavigationDispatchState {navigate_id: Some(1),- owner: crate::conn::CommandOwnerScope::for_session("SID-target"),+ owner,result_projection: NavigationResultProjection::Cdp(json!({"frameId": "TID-target","loaderId": "LOADER-target",@@ -134,11 +139,19 @@ async fn buffered_navigation_for_inactive_session_carries_its_target_engine() {.expect("buffered target navigation should prepare");let loaded =commit_navigation_outcome_for_session_test(&mut conn, outcome, Some("SID-target")).await;- let target_engine = loaded- .navigation_engine_replacement()- .expect("target-scoped buffered navigation must carry its engine to commit");+ let target_engine = conn+ .browser_context_by_id("BID-target")+ .and_then(|context| context.page_navigation_engine("TID-target"))+ .expect("inactive target must keep its navigation engine after completion");+ let retained_client = target_engine+ .resource_request_client()+ .expect("resident target engine must keep a resource request client");let target_renderer_owner = target_engine.renderer_owner_id_for_diagnostics();+ assert!(+ resident_client.shares_page_network_policy_with(&retained_client),+ "navigation completion must not replace the target's resident engine policy"+ );assert_eq!(loaded.page.renderer_owner_local_host_id().as_u64(),target_renderer_owner,diff --git a/moli-protocol/src/domains/fetch/commands.rs b/moli-protocol/src/domains/fetch/commands.rsindex e57790b50..d7dd9d86f 100644--- a/moli-protocol/src/domains/fetch/commands.rs+++ b/moli-protocol/src/domains/fetch/commands.rs@@ -1851,12 +1851,11 @@ fn continue_streaming_document_response_in_background(document_navigation_token.clone(),navigation.clone(),);- let (engine, navigation_result) =+ let navigation_result =prepared_document.resume_streaming(response, Some(body_completion_sink));let _ = sender.send(page::BackgroundNavigationCompletion::new(document_navigation_token,navigation,- engine,Ok(navigation_result),));});@@ -1877,11 +1876,10 @@ fn continue_streaming_document_response_in_background(document_navigation_token.clone(),navigation.clone(),);- let (engine, navigation_result) = job.run(Some(body_completion_sink)).await;+ let navigation_result = job.run(Some(body_completion_sink)).await;let _ = sender.send(page::BackgroundNavigationCompletion::new(document_navigation_token,navigation,- engine,navigation_result,));});diff --git a/moli-protocol/src/domains/network/main_document_progress/mod.rs b/moli-protocol/src/domains/network/main_document_progress/mod.rsindex bbfb41049..fd9014f0b 100644--- a/moli-protocol/src/domains/network/main_document_progress/mod.rs+++ b/moli-protocol/src/domains/network/main_document_progress/mod.rs@@ -19,7 +19,7 @@ use url::Url;use crate::conn::{BackgroundEventSender, BackgroundProtocolEvent, CapturedBody, CdpConnection,CompletedDownloadBodyArtifact, DownloadNavigation, LoadedNavigation, NavigationDispatchState,- NavigationEngineHandoff, NavigationLoadOutcome, ResponseCommitReady, TargetRuntimeSlot,+ NavigationLoadOutcome, ResponseCommitReady, TargetRuntimeSlot,};#[cfg(test)]@@ -42,7 +42,6 @@ pub(crate) struct MaterializedLoadedDocumentProgress {pub(crate) renderer_output_predecessor: Option<RendererOutputFence>,pub(crate) main_document_commit: Option<Arc<RendererMainDocumentCommit>>,pub(crate) progress_gate: MainDocumentProgressGate,- pub(crate) navigation_engine_handoff: NavigationEngineHandoff,pub(crate) network_error_page: Option<crate::conn::NetworkErrorPageNavigation>,}@@ -309,7 +308,6 @@ pub(crate) fn materialize_loaded_navigation_progress(renderer_output_predecessor,main_document_commit,document_progress_transfer,- navigation_engine_handoff,network_error_page,..} = navigation;@@ -330,7 +328,6 @@ pub(crate) fn materialize_loaded_navigation_progress(renderer_output_predecessor,main_document_commit,progress_gate,- navigation_engine_handoff,network_error_page,}}diff --git a/moli-protocol/src/domains/page/navigation.rs b/moli-protocol/src/domains/page/navigation.rsindex 5cb45e234..73be7206e 100644--- a/moli-protocol/src/domains/page/navigation.rs+++ b/moli-protocol/src/domains/page/navigation.rs@@ -14,7 +14,6 @@ use moli_core::page::{ChildFrameDocumentOpenedSnapshot, CompletedPageCommand, PendingPageCommand,SameDocumentHistoryUpdate,};-use moli_core::runtime::NavigationEngine;use moli_fetch::NET_ERR_ABORTED_ERROR_TEXT;use moli_url_policy::{LocalFileNavigationAccess, route_navigation_url};use serde_json::{Value, json};@@ -23,10 +22,9 @@ use url::Url;use crate::conn::{BackgroundNavigationLoadJob, BackgroundProtocolEvent, CapturedBody, CdpConnection,CdpSessionRoute, Cmd, CommandDispatchContext, CommandOwnerScope, DocumentNavigationToken,- FetchRequestStage, NavigationDispatchState, NavigationEngineHandoff, NavigationLoadOutcome,- NavigationRequestLoadPolicy, NavigationResultProjection,- NavigationSourceDocumentSecurityContext, PendingFetchNavigation, ResponseStageUrlMatchPolicy,- monotonic_timestamp_seconds,+ FetchRequestStage, NavigationDispatchState, NavigationLoadOutcome, NavigationRequestLoadPolicy,+ NavigationResultProjection, NavigationSourceDocumentSecurityContext, PendingFetchNavigation,+ ResponseStageUrlMatchPolicy, monotonic_timestamp_seconds,};use moli_cookie_jar::{NetworkCookieRequestContext, StoredCookieQueryReport};@@ -62,7 +60,6 @@ pub(super) struct CompletedNavigateLoadCommand {prefix_events: Vec<BackgroundProtocolEvent>,token: DocumentNavigationToken,state: NavigationDispatchState,- engine: NavigationEngine,navigation: Result<NavigationLoadOutcome, String>,}@@ -152,12 +149,11 @@ impl CompletedSameDocumentHistoryTraversalCommand {impl PendingNavigateLoadCommand {pub(super) async fn wait(self) -> CompletedNavigateLoadCommand {- let (engine, navigation, _early_result_sent) = self.job.run(None).await;+ let (navigation, _early_result_sent) = self.job.run(None).await;CompletedNavigateLoadCommand {prefix_events: self.prefix_events,token: self.token,state: self.state,- engine,navigation,}}@@ -395,7 +391,6 @@ pub(crate) struct MaterializedNavigationCompletion {token: DocumentNavigationToken,state: NavigationDispatchState,navigation: network::MaterializedNavigationLoadOutcome,- engine_handoff: NavigationEngineHandoff,}impl MaterializedNavigationCompletion {@@ -408,15 +403,9 @@ impl MaterializedNavigationCompletion {token,state,navigation,- engine_handoff: NavigationEngineHandoff::retained_by_owner(),}}- pub(crate) fn with_navigation_engine_replacement(mut self, engine: NavigationEngine) -> Self {- self.engine_handoff = NavigationEngineHandoff::replacement(engine);- self- }-pub(crate) fn is_current_for_connection(&self, conn: &CdpConnection) -> bool {conn.accepts_pending_document_navigation_for_owner(&self.state.owner, &self.token)}@@ -439,9 +428,8 @@ impl MaterializedNavigationCompletion {DocumentNavigationToken,NavigationDispatchState,network::MaterializedNavigationLoadOutcome,- NavigationEngineHandoff,) {- (self.token, self.state, self.navigation, self.engine_handoff)+ (self.token, self.state, self.navigation)}}@@ -543,7 +531,6 @@ impl BackgroundNavigationCompletion {pub struct BackgroundNavigationLifecycleCompletion {token: DocumentNavigationToken,state: NavigationDispatchState,- engine: NavigationEngine,navigation: Result<NavigationLoadOutcome, String>,ready_at: std::time::Instant,}@@ -552,13 +539,11 @@ impl BackgroundNavigationLifecycleCompletion {pub(crate) fn new(token: DocumentNavigationToken,state: NavigationDispatchState,- engine: NavigationEngine,navigation: Result<NavigationLoadOutcome, String>,) -> Self {Self {token,state,- engine,navigation,ready_at: std::time::Instant::now(),}@@ -568,10 +553,6 @@ impl BackgroundNavigationLifecycleCompletion {&self.token}- pub(crate) fn is_current_for_connection(&self, conn: &CdpConnection) -> bool {- conn.accepts_pending_document_navigation_for_owner(&self.state.owner, &self.token)- }-pub(crate) fn requested_url(&self) -> &str {self.state.requested_url.as_str()}@@ -580,38 +561,15 @@ impl BackgroundNavigationLifecycleCompletion {self.ready_at.elapsed().as_millis()}- /// Materialize the background navigation outcome into a queued- /// `MaterializedNavigationCompletion`. `replace_owner_engine` should be- /// `false`- /// when the completion's token is no longer current — stale completions- /// still flow into the materialized queue so the drain can emit a- /// terminal abort response for any outstanding `navigate_id`, but the- /// stale background engine must not keep a renderer owner alive.- pub(crate) fn materialize_with_engine_replacement(- self,- conn: &mut CdpConnection,- replace_owner_engine: bool,- ) -> MaterializedNavigationCompletion {+ pub(crate) fn materialize(self, conn: &mut CdpConnection) -> MaterializedNavigationCompletion {let Self {token,state,- engine,navigation,ready_at: _,} = self;- let should_replace_owner_engine = replace_owner_engine- && matches!(- navigation,- Ok(NavigationLoadOutcome::ResponseCommitReady(_)- | NavigationLoadOutcome::Loaded(_))- );let navigation = network::materialize_navigation_load_result(conn, &state, navigation);- let completion = MaterializedNavigationCompletion::new(token, state, navigation);- if should_replace_owner_engine {- completion.with_navigation_engine_replacement(engine)- } else {- completion- }+ MaterializedNavigationCompletion::new(token, state, navigation)}}@@ -619,11 +577,10 @@ impl BackgroundNavigationCompletion {pub(crate) fn new(token: DocumentNavigationToken,state: NavigationDispatchState,- engine: NavigationEngine,navigation: Result<NavigationLoadOutcome, String>,) -> Self {Self::Lifecycle(Box::new(BackgroundNavigationLifecycleCompletion::new(- token, state, engine, navigation,+ token, state, navigation,)))}@@ -2993,7 +2950,7 @@ fn start_navigate_to_url_command_with_background_policy_and_request(document_navigation_token.clone(),completion_state.clone(),);- let (engine, navigation, early_result_sent) = job.run(Some(body_completion_sink)).await;+ let (navigation, early_result_sent) = job.run(Some(body_completion_sink)).await;if early_result_sent {completion_state.navigate_id = None;}@@ -3007,7 +2964,6 @@ fn start_navigate_to_url_command_with_background_policy_and_request(let _ = sender.send(BackgroundNavigationCompletion::new(document_navigation_token,completion_state,- engine,navigation,));});@@ -3089,22 +3045,10 @@ pub(super) async fn complete_pending_navigate_load_command(prefix_events,token,state,- engine,navigation,} = completed;- let is_current = conn.accepts_pending_document_navigation_for_owner(&state.owner, &token);- let should_replace_owner_engine = is_current- && matches!(- navigation,- Ok(NavigationLoadOutcome::ResponseCommitReady(_) | NavigationLoadOutcome::Loaded(_))- );let navigation = network::materialize_navigation_load_result(conn, &state, navigation);let completion = MaterializedNavigationCompletion::new(token, state, navigation);- let completion = if should_replace_owner_engine {- completion.with_navigation_engine_replacement(engine)- } else {- completion- };let mut output = CommandOutputBuffer::default();output.extend_background_events_after_messages(prefix_events);conn.drain_materialized_navigation_completion_into_buffer(diff --git a/moli-protocol/src/domains/page/navigation_commit.rs b/moli-protocol/src/domains/page/navigation_commit.rsindex f8cdda5f7..caf5b07ae 100644--- a/moli-protocol/src/domains/page/navigation_commit.rs+++ b/moli-protocol/src/domains/page/navigation_commit.rs@@ -42,7 +42,6 @@ pub(super) async fn commit_loaded_navigation_async(renderer_output_predecessor,main_document_commit,progress_gate,- navigation_engine_handoff,network_error_page,} = navigation;let target_url = network_error_page@@ -135,10 +134,6 @@ pub(super) async fn commit_loaded_navigation_async(navigation_activity.defer_initial_renderer_document_lifecycle_events_until_load_boundary(deferred_initial_renderer_document_lifecycle_events,);- if let Some(engine) = navigation_engine_handoff.into_replacement() {- conn.adopt_loaded_navigation_engine_for_owner(&navigation_activity.state().owner, engine);- }-// Keep the loaded commit tail boxed: the target/Patchright CDP test thread// has historically hit stack limits when this future is inlined.Box::pin(async move {diff --git a/moli-protocol/src/domains/page/tests/document_content.rs b/moli-protocol/src/domains/page/tests/document_content.rsindex 5367726ec..612165ce2 100644--- a/moli-protocol/src/domains/page/tests/document_content.rs+++ b/moli-protocol/src/domains/page/tests/document_content.rs@@ -14,7 +14,6 @@ async fn install_document_content_test_page(ctx: &mut TestContext, url: &str) {.load_navigation_via_runtime_for_session_owner_async(Some("SID-1"), url).await.expect("document-content test page should load");- let navigation_engine = navigation.take_navigation_engine_replacement();let artifacts = navigation.page_creation_artifacts;{let browser_context = ctx.conn.browser_context.as_mut().expect("browser context");@@ -55,12 +54,6 @@ async fn install_document_content_test_page(ctx: &mut TestContext, url: &str) {LOADER_ID.to_owned(),);assert!(binding.is_some(), "renderer lifecycle should bind");- if let Some(navigation_engine) = navigation_engine {- ctx.conn.adopt_loaded_navigation_engine_for_owner(- &crate::conn::CommandOwnerScope::for_session("SID-1"),- navigation_engine,- );- }// The fixture commits an already-running renderer Page directly instead// of going through the production navigation command. Route that exact// Document's initial lifecycle publication before enabling observers.diff --git a/moli-protocol/src/domains/page/tests/lifecycle.rs b/moli-protocol/src/domains/page/tests/lifecycle.rsindex 4bc10efa0..71b6e0b7e 100644--- a/moli-protocol/src/domains/page/tests/lifecycle.rs+++ b/moli-protocol/src/domains/page/tests/lifecycle.rs@@ -271,12 +271,11 @@ async fn install_runtime_document_replacement_test_page(ctx: &mut TestContext) -"SID-1","about:blank",);- let mut navigation = ctx+ let navigation = ctx.conn.load_navigation_via_runtime_async("data:text/html,<body>initial</body>").await.expect("runtime replacement fixture page should load");- let navigation_engine = navigation.take_navigation_engine_replacement();let artifacts = navigation.page_creation_artifacts;ctx.conn.browser_context@@ -298,12 +297,6 @@ async fn install_runtime_document_replacement_test_page(ctx: &mut TestContext) -2,"prepared data navigation commits at DOMContentLoaded; load remains renderer-owned tail work");- if let Some(navigation_engine) = navigation_engine {- ctx.conn.adopt_loaded_navigation_engine_for_owner(- &crate::conn::CommandOwnerScope::for_session("SID-1"),- navigation_engine,- );- }ctx.enable_dom_events_for_test(Some("SID-1"));ctx.process_async(json!({@@ -826,12 +819,11 @@ async fn set_lifecycle_events_enabled_sets_flag() {async fn set_lifecycle_events_enabled_replays_loaded_page_events() {let mut ctx = TestContext::new();load_bc_with_session(&mut ctx, "BID-1", "TID-1", "SID-1", "about:blank");- let mut navigation = ctx+ let navigation = ctx.conn.load_navigation_via_runtime_async("data:text/html,<body>hello</body>").await.expect("page should load");- let navigation_engine = navigation.take_navigation_engine_replacement();let dom_timestamp = navigation.page_creation_artifacts.lifecycle_snapshot@@ -855,12 +847,6 @@ async fn set_lifecycle_events_enabled_replays_loaded_page_events() {);assert!(binding.is_some());assert_eq!(initial_events.len(), 2);- if let Some(navigation_engine) = navigation_engine {- ctx.conn.adopt_loaded_navigation_engine_for_owner(- &crate::conn::CommandOwnerScope::for_session("SID-1"),- navigation_engine,- );- }let load_timestamp = wait_for_visible_renderer_load(&mut ctx, "SID-1").await.timestamp_micros as f64@@ -908,12 +894,11 @@ async fn set_lifecycle_events_enabled_replays_only_protocol_visible_load_state()"SID-visible","about:blank",);- let mut navigation = ctx+ let navigation = ctx.conn.load_navigation_via_runtime_async("data:text/html,<body>visible lifecycle</body>").await.expect("page should load");- let navigation_engine = navigation.take_navigation_engine_replacement();let artifacts = navigation.page_creation_artifacts;ctx.conn.browser_context@@ -931,12 +916,6 @@ async fn set_lifecycle_events_enabled_replays_only_protocol_visible_load_state());assert!(binding.is_some());assert_eq!(initial_events.len(), 2);- if let Some(navigation_engine) = navigation_engine {- ctx.conn.adopt_loaded_navigation_engine_for_owner(- &crate::conn::CommandOwnerScope::for_session("SID-visible"),- navigation_engine,- );- }assert!(ctx.conn.begin_renderer_document_load_visibility_barrier_for_owner(@@ -1011,12 +990,11 @@ async fn set_lifecycle_events_enabled_is_session_local_for_active_attached_sessi"SID-primary","about:blank",);- let mut navigation = ctx+ let navigation = ctx.conn.load_navigation_via_runtime_async("data:text/html,<body>active attached lifecycle</body>").await.expect("page should load");- let navigation_engine = navigation.take_navigation_engine_replacement();let artifacts = navigation.page_creation_artifacts;let browser_context = ctx.conn.browser_context.as_mut().unwrap();browser_context@@ -1036,12 +1014,6 @@ async fn set_lifecycle_events_enabled_is_session_local_for_active_attached_sessi);assert!(binding.is_some());assert_eq!(initial_events.len(), 2);- if let Some(navigation_engine) = navigation_engine {- ctx.conn.adopt_loaded_navigation_engine_for_owner(- &crate::conn::CommandOwnerScope::for_session("SID-attached"),- navigation_engine,- );- }let _ = wait_for_visible_renderer_load(&mut ctx, "SID-attached").await;ctx.sent.clear();diff --git a/moli-protocol/src/testing.rs b/moli-protocol/src/testing.rsindex 697bdf895..efefdd0d9 100644--- a/moli-protocol/src/testing.rs+++ b/moli-protocol/src/testing.rs@@ -305,7 +305,7 @@ impl TestContext {async fn install_loaded_navigation_fixture_for_session_owner(&mut self,- mut navigation: crate::conn::LoadedNavigation,+ navigation: crate::conn::LoadedNavigation,session_id: Option<&str>,) {let owner = crate::conn::CommandOwnerScope::capture(&self.conn, session_id);@@ -314,7 +314,6 @@ impl TestContext {.target_owner_identity_for_owner(&owner).expect("navigation fixture requires an installed browser context");let target_id = target_id.expect("navigation fixture requires an exact target");- let navigation_engine = navigation.take_navigation_engine_replacement();let renderer_output_predecessor = navigation.renderer_output_predecessor;let page_creation_artifacts = navigation.page_creation_artifacts;let final_url = navigation.final_url;@@ -354,10 +353,6 @@ impl TestContext {);let binding =binding.expect("navigation fixture must install its exact renderer Document binding");- if let Some(navigation_engine) = navigation_engine {- self.conn- .adopt_loaded_navigation_engine_for_owner(&owner, navigation_engine);- }assert_eq!(self.conn.target_root_document_lifecycle_identity_for_owner(&owner,),diff --git a/moli-renderer-v8/src/network/policy.rs b/moli-renderer-v8/src/network/policy.rsindex 97de46171..ce801a5e1 100644--- a/moli-renderer-v8/src/network/policy.rs+++ b/moli-renderer-v8/src/network/policy.rs@@ -143,13 +143,6 @@ impl PageNetworkPolicy {self.memory_cache_partition_id() == other.memory_cache_partition_id()}- /// Keeps this policy's current state while adopting another Page policy's- /// stable renderer memory-cache capability.- pub fn adopt_memory_cache_partition_from(&mut self, source: &Self) {- let source_partition_id = source.memory_cache_partition_id();- self.state.lock().memory_cache_partition_id = source_partition_id;- }-pub fn from_snapshot(snapshot: PageNetworkPolicySnapshot) -> Self {Self::from_snapshot_with_memory_cache_partition(snapshot, next_memory_cache_partition_id())}