Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
fix(renderer): follow navigation queued at reached load milestone
lanyue-llk7e87eef4f407
diff --git a/moli-renderer-v8/src/runtime/owner/page_creation.rs b/moli-renderer-v8/src/runtime/owner/page_creation.rsindex 400a258f0..075eba2c8 100644--- a/moli-renderer-v8/src/runtime/owner/page_creation.rs+++ b/moli-renderer-v8/src/runtime/owner/page_creation.rs@@ -1,5 +1,8 @@use super::*;-use crate::runtime::owner_local_store::take_staged_auxiliary_page_on_bound_owner_local_store;+use crate::runtime::owner_local_store::{+ reconcile_navigation_lifecycle_observation,+ take_staged_auxiliary_page_on_bound_owner_local_store,+};impl RendererOwnerHandle {pub(super) async fn run_owner_lane_local_task<R, F>(&self, future: F) -> Result<R>@@ -519,6 +522,10 @@ impl RendererOwnerHandle {Err(error) => return Err(error).into(),};let observation = observe_document_lifecycle_on_entry(&mut entry, document, target_stage);+ let observation = reconcile_navigation_lifecycle_observation(+ observation,+ entry.page_vm().vm().has_pending_location_navigation(),+ );match observation {DocumentLifecycleObserverOutcome::NavigationPendingif completion.returns_with_pending_location_navigation() =>diff --git a/moli-renderer-v8/src/runtime/owner_local_store/bound.rs b/moli-renderer-v8/src/runtime/owner_local_store/bound.rsindex c1ecf33c3..89e8d59db 100644--- a/moli-renderer-v8/src/runtime/owner_local_store/bound.rs+++ b/moli-renderer-v8/src/runtime/owner_local_store/bound.rs@@ -933,7 +933,7 @@ pub(in crate::runtime) fn observe_document_lifecycle_on_entry(entry.observe_document_lifecycle(document, target_stage)}-pub(super) fn reconcile_page_creation_lifecycle_observation(+pub(in crate::runtime) fn reconcile_navigation_lifecycle_observation(observation: DocumentLifecycleObserverOutcome,has_pending_location_navigation: bool,) -> DocumentLifecycleObserverOutcome {diff --git a/moli-renderer-v8/src/runtime/owner_local_store/mod.rs b/moli-renderer-v8/src/runtime/owner_local_store/mod.rsindex 104a0d95e..dc58fbc3a 100644--- a/moli-renderer-v8/src/runtime/owner_local_store/mod.rs+++ b/moli-renderer-v8/src/runtime/owner_local_store/mod.rs@@ -1118,7 +1118,7 @@ impl RendererOwnerLocalStore {// `FollowBeforeReply` must observe that navigation before publishing// the old Document; generic lifecycle observers still treat the// milestone itself as reached.- let observation = bound::reconcile_page_creation_lifecycle_observation(+ let observation = bound::reconcile_navigation_lifecycle_observation(observation,entry.page_vm().vm().has_pending_location_navigation(),);diff --git a/moli-renderer-v8/src/runtime/owner_local_store/tests.rs b/moli-renderer-v8/src/runtime/owner_local_store/tests.rsindex af941af93..26cb85c03 100644--- a/moli-renderer-v8/src/runtime/owner_local_store/tests.rs+++ b/moli-renderer-v8/src/runtime/owner_local_store/tests.rs@@ -251,7 +251,7 @@ mod navigation_dispatch_tests {#[test]fn page_creation_prioritizes_navigation_enqueued_by_reached_milestone() {assert_eq!(- reconcile_page_creation_lifecycle_observation(+ reconcile_navigation_lifecycle_observation(DocumentLifecycleObserverOutcome::Reached,true,),@@ -268,7 +268,7 @@ mod navigation_dispatch_tests {};assert_eq!(- reconcile_page_creation_lifecycle_observation(+ reconcile_navigation_lifecycle_observation(DocumentLifecycleObserverOutcome::Interrupted(termination),true,),diff --git a/moli-test-support/src/routes_core.rs b/moli-test-support/src/routes_core.rsindex 7a6781fc1..1895d3e6d 100644--- a/moli-test-support/src/routes_core.rs+++ b/moli-test-support/src/routes_core.rs@@ -703,6 +703,23 @@ pub(super) async fn location_nav_chain_mid_page() -> Html<&'static str> {Html(LOCATION_NAV_CHAIN_MID_HTML)}+pub(super) async fn location_nav_load_chain_page(+ Query(params): Query<HashMap<String, String>>,+) -> Html<String> {+ let remaining = params+ .get("remaining")+ .and_then(|value| value.parse::<u8>().ok())+ .unwrap_or(1);+ let destination = if remaining > 1 {+ format!("/location-nav/load-chain?remaining={}", remaining - 1)+ } else {+ "/location-nav/target?from=load-chain".to_owned()+ };+ Html(format!(+ "<!doctype html><body>Intermediate page<script>addEventListener('load',()=>{{document.body.setAttribute('data-load','yes');location.href='{destination}'}})</script>"+ ))+}+pub(super) async fn location_nav_chain_timeout_source_page() -> Html<&'static str> {Html(LOCATION_NAV_CHAIN_TIMEOUT_SOURCE_HTML)}diff --git a/moli-test-support/src/server_routes.rs b/moli-test-support/src/server_routes.rsindex 633dbafc1..bfbfd4e77 100644--- a/moli-test-support/src/server_routes.rs+++ b/moli-test-support/src/server_routes.rs@@ -176,6 +176,7 @@ pub(super) fn build_router() -> Router {get(location_nav_chain_source_page),).route("/location-nav/chain-mid", get(location_nav_chain_mid_page))+ .route("/location-nav/load-chain", get(location_nav_load_chain_page)).route("/location-nav/chain-timeout-source",get(location_nav_chain_timeout_source_page),diff --git a/moli/tests/fetch_cli/eval.rs b/moli/tests/fetch_cli/eval.rsindex e0308e58c..2b92f3ba8 100644--- a/moli/tests/fetch_cli/eval.rs+++ b/moli/tests/fetch_cli/eval.rs@@ -154,6 +154,67 @@ fn eval_dumps_destination_after_interaction_navigation() -> Result<()> {Ok(())}+#[test]+fn eval_follows_load_handler_navigation_chains_like_direct_fetch() -> Result<()> {+ let runtime = tokio::runtime::Runtime::new()?;+ let server = runtime.block_on(FixtureServer::spawn())?;+ let url = server.url("/static");+ for remaining in [1, 2] {+ let destination = format!("/location-nav/load-chain?remaining={remaining}");+ let script = format!("location.href='{destination}';undefined");+ let path = unique_temp_file_path("load-chain", "navigate.js")?;+ std::fs::write(&path, &script)?;+ for dump in ["html", "markdown", "json"] {+ let direct = run_moli([+ "moli",+ "fetch",+ "--log-level",+ "error",+ "--http-no-proxy",+ "*",+ "--wait-until",+ "load",+ "--dump",+ dump,+ &server.url(&destination),+ ])?;+ assert!(direct.status.success(), "{}", clean_output(&direct.stderr));+ let direct_text = clean_output(&direct.stdout);+ assert!(+ direct_text.contains("location-target=load-chain"),+ "{direct_text}"+ );+ assert!(!direct_text.contains("Intermediate page"), "{direct_text}");+ for source in ["--eval", "--eval-file"] {+ let expression = if source == "--eval" {+ OsStr::new(&script)+ } else {+ path.as_os_str()+ };+ let output = run_eval_source(&url, source, expression, &["--dump", dump])?;+ assert!(output.status.success(), "{}", clean_output(&output.stderr));+ let text = clean_output(&output.stdout);+ assert!(text.contains("location-target=load-chain"), "{text}");+ assert!(!text.contains("Intermediate page"), "{text}");+ if dump == "json" {+ let result: serde_json::Value = serde_json::from_slice(&output.stdout)?;+ let baseline: serde_json::Value = serde_json::from_slice(&direct.stdout)?;+ assert_eq!(+ result["final_url"],+ server.url("/location-nav/target?from=load-chain")+ );+ assert_eq!(result["final_url"], baseline["final_url"]);+ } else {+ assert_eq!(text, direct_text);+ }+ }+ }+ std::fs::remove_file(path)?;+ }+ runtime.block_on(server.shutdown());+ Ok(())+}+#[test]fn eval_can_use_realtime_audio_oscillator_and_analyser_shims() -> Result<()> {let output = run_eval(