Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(history): preserve joint length for initial child documents (#763)

Donough Liu7eb644439496
diff --git a/moli-core/tests/child_context.rs b/moli-core/tests/child_context.rs
index 0073ded31..5cb912663 100644
--- a/moli-core/tests/child_context.rs
+++ b/moli-core/tests/child_context.rs
@@ -25,7 +25,7 @@ async fn child_browsing_context_initial_history_seed_keeps_current_entry_index_z
page.serialize_html_async()
.await
.unwrap()
- .contains("data-top-history-length=\"2\""),
+ .contains("data-top-history-length=\"1\""),
"{}",
page.serialize_html_async().await.unwrap()
);
@@ -33,7 +33,7 @@ async fn child_browsing_context_initial_history_seed_keeps_current_entry_index_z
page.serialize_html_async()
.await
.unwrap()
- .contains("data-child-history-length=\"2\""),
+ .contains("data-child-history-length=\"1\""),
"{}",
page.serialize_html_async().await.unwrap()
);
diff --git a/moli-core/tests/history_child.rs b/moli-core/tests/history_child.rs
index 7fca0b40f..6c1b6875b 100644
--- a/moli-core/tests/history_child.rs
+++ b/moli-core/tests/history_child.rs
@@ -913,7 +913,7 @@ async fn child_browsing_context_attribute_navigation_preserves_local_history() -
page.serialize_html_async()
.await
.unwrap()
- .contains("data-child-history-length=\"4\""),
+ .contains("data-child-history-length=\"3\""),
"{}",
page.serialize_html_async().await.unwrap()
);
@@ -983,7 +983,7 @@ async fn child_browsing_context_history_relative_urls_stay_child_local() -> Resu
page.serialize_html_async()
.await
.unwrap()
- .contains("data-child-history-length=\"3\""),
+ .contains("data-child-history-length=\"2\""),
"{}",
page.serialize_html_async().await.unwrap()
);
@@ -1089,7 +1089,7 @@ async fn child_browsing_context_history_relative_urls_stay_child_local() -> Resu
page.serialize_html_async()
.await
.unwrap()
- .contains("data-child-path-back-history-length=\"3\""),
+ .contains("data-child-path-back-history-length=\"2\""),
"{}",
page.serialize_html_async().await.unwrap()
);
@@ -1527,7 +1527,7 @@ async fn child_browsing_context_navigation_push_state_stays_window_local() -> Re
page.serialize_html_async()
.await
.unwrap()
- .contains("data-child-history-length-after-load=\"3\""),
+ .contains("data-child-history-length-after-load=\"2\""),
"{}",
page.serialize_html_async().await.unwrap()
);
@@ -2256,14 +2256,14 @@ async fn child_browsing_context_navigation_same_document_push_result_surface_mat
);
assert!(
page.serialize_html_async().await.unwrap().contains(&format!(
- "data-sync=\"hash=#dest|len=3|committed=false|finished=false|history=null|entry={{"step":7}}|listener=1|property=1|from={child_url}|propertyFrom={child_url}|navType=push|propertyNavType=push|order=cec:push:{child_url},popstate:#dest\""
+ "data-sync=\"hash=#dest|len=2|committed=false|finished=false|history=null|entry={{"step":7}}|listener=1|property=1|from={child_url}|propertyFrom={child_url}|navType=push|propertyNavType=push|order=cec:push:{child_url},popstate:#dest\""
)),
"{}",
page.serialize_html_async().await.unwrap()
);
assert!(
page.serialize_html_async().await.unwrap().contains(&format!(
- "data-timeout=\"hash=#dest|len=3|committed=true|finished=true|history=null|entry={{"step":7}}|listener=1|property=1|from={child_url}|propertyFrom={child_url}|navType=push|propertyNavType=push|order=cec:push:{child_url},popstate:#dest,cec-micro:#dest:null,committed:#dest:true,finished:#dest:true,hashchange:#dest\""
+ "data-timeout=\"hash=#dest|len=2|committed=true|finished=true|history=null|entry={{"step":7}}|listener=1|property=1|from={child_url}|propertyFrom={child_url}|navType=push|propertyNavType=push|order=cec:push:{child_url},popstate:#dest,cec-micro:#dest:null,committed:#dest:true,finished:#dest:true,hashchange:#dest\""
)),
"{}",
page.serialize_html_async().await.unwrap()
@@ -2305,14 +2305,14 @@ async fn child_browsing_context_navigation_same_document_replace_result_surface_
);
assert!(
page.serialize_html_async().await.unwrap().contains(&format!(
- "data-sync=\"hash=#dest|len=2|committed=false|finished=false|history=null|entry={{"step":9}}|listener=1|property=1|from={child_url}|propertyFrom={child_url}|navType=replace|propertyNavType=replace|order=cec:replace:{child_url},popstate:#dest\""
+ "data-sync=\"hash=#dest|len=1|committed=false|finished=false|history=null|entry={{"step":9}}|listener=1|property=1|from={child_url}|propertyFrom={child_url}|navType=replace|propertyNavType=replace|order=cec:replace:{child_url},popstate:#dest\""
)),
"{}",
page.serialize_html_async().await.unwrap()
);
assert!(
page.serialize_html_async().await.unwrap().contains(&format!(
- "data-timeout=\"hash=#dest|len=2|committed=true|finished=true|history=null|entry={{"step":9}}|listener=1|property=1|from={child_url}|propertyFrom={child_url}|navType=replace|propertyNavType=replace|order=cec:replace:{child_url},popstate:#dest,cec-micro:#dest:null,committed:#dest:true,finished:#dest:true,hashchange:#dest\""
+ "data-timeout=\"hash=#dest|len=1|committed=true|finished=true|history=null|entry={{"step":9}}|listener=1|property=1|from={child_url}|propertyFrom={child_url}|navType=replace|propertyNavType=replace|order=cec:replace:{child_url},popstate:#dest,cec-micro:#dest:null,committed:#dest:true,finished:#dest:true,hashchange:#dest\""
)),
"{}",
page.serialize_html_async().await.unwrap()
@@ -2366,14 +2366,14 @@ async fn child_browsing_context_navigation_result_surface_exists_in_child_script
);
assert!(
page.serialize_html_async().await.unwrap().contains(&format!(
- "data-source-sync=\"false|false|{child_source_url}|2|0|{child_source_url}||replace|true|0|0\""
+ "data-source-sync=\"false|false|{child_source_url}|1|0|{child_source_url}||replace|true|0|0\""
)),
"{}",
page.serialize_html_async().await.unwrap()
);
assert!(
page.serialize_html_async().await.unwrap().contains(&format!(
- "data-source-timeout=\"false|false|{child_source_url}|2|0|{child_source_url}||replace|true|0|0\""
+ "data-source-timeout=\"false|false|{child_source_url}|1|0|{child_source_url}||replace|true|0|0\""
)),
"{}",
page.serialize_html_async().await.unwrap()
@@ -2760,14 +2760,14 @@ async fn child_browsing_context_navigation_push_result_surface_exists_in_child_s
);
assert!(
page.serialize_html_async().await.unwrap().contains(&format!(
- "data-source-sync=\"false|false|{child_source_url}|2|0|{child_source_url}||replace|true|0|0\""
+ "data-source-sync=\"false|false|{child_source_url}|1|0|{child_source_url}||replace|true|0|0\""
)),
"{}",
page.serialize_html_async().await.unwrap()
);
assert!(
page.serialize_html_async().await.unwrap().contains(&format!(
- "data-source-timeout=\"false|false|{child_source_url}|2|0|{child_source_url}||replace|true|0|0\""
+ "data-source-timeout=\"false|false|{child_source_url}|1|0|{child_source_url}||replace|true|0|0\""
)),
"{}",
page.serialize_html_async().await.unwrap()
@@ -2803,7 +2803,7 @@ async fn child_browsing_context_navigation_push_result_surface_exists_in_child_s
.await
.unwrap()
.contains(&format!(
- "data-dest-current=\"{child_destination_url}|3|1\""
+ "data-dest-current=\"{child_destination_url}|2|1\""
)),
"{}",
page.serialize_html_async().await.unwrap()
@@ -3934,7 +3934,7 @@ async fn child_browsing_context_fragment_navigation_persists_through_attribute_n
page.serialize_html_async()
.await
.unwrap()
- .contains("data-child-history-length-initial=\"2\""),
+ .contains("data-child-history-length-initial=\"1\""),
"{}",
page.serialize_html_async().await.unwrap()
);
@@ -3953,7 +3953,7 @@ async fn child_browsing_context_fragment_navigation_persists_through_attribute_n
page.serialize_html_async()
.await
.unwrap()
- .contains("data-child-history-length-after-push=\"3\""),
+ .contains("data-child-history-length-after-push=\"2\""),
"{}",
page.serialize_html_async().await.unwrap()
);
@@ -3972,7 +3972,7 @@ async fn child_browsing_context_fragment_navigation_persists_through_attribute_n
page.serialize_html_async()
.await
.unwrap()
- .contains("data-child-history-length=\"4\""),
+ .contains("data-child-history-length=\"3\""),
"{}",
page.serialize_html_async().await.unwrap()
);
@@ -4015,8 +4015,8 @@ async fn child_browsing_context_fragment_navigation_persists_through_attribute_n
}
#[tokio::test]
-async fn child_browsing_context_initial_joint_history_length_updates_before_following_parent_script()
--> Result<()> {
+async fn child_browsing_context_initial_navigation_keeps_joint_history_length_stable() -> Result<()>
+{
let server = FixtureServer::spawn().await?;
let browser = Browser::new(AppConfig::default())?;
@@ -4028,7 +4028,7 @@ async fn child_browsing_context_initial_joint_history_length_updates_before_foll
page.serialize_html_async()
.await
.unwrap()
- .contains("data-top-sync-history-length=\"2\""),
+ .contains("data-top-sync-history-length=\"1\""),
"{}",
page.serialize_html_async().await.unwrap()
);
@@ -4036,7 +4036,7 @@ async fn child_browsing_context_initial_joint_history_length_updates_before_foll
page.serialize_html_async()
.await
.unwrap()
- .contains("data-top-load-history-length=\"2\""),
+ .contains("data-top-load-history-length=\"1\""),
"{}",
page.serialize_html_async().await.unwrap()
);
@@ -4044,7 +4044,7 @@ async fn child_browsing_context_initial_joint_history_length_updates_before_foll
page.serialize_html_async()
.await
.unwrap()
- .contains("data-child-load-history-length=\"2\""),
+ .contains("data-child-load-history-length=\"1\""),
"{}",
page.serialize_html_async().await.unwrap()
);
@@ -4136,7 +4136,7 @@ async fn child_browsing_context_location_hash_assignment_dispatches_local_popsta
page.serialize_html_async()
.await
.unwrap()
- .contains("data-top-history-unchanged=\"true\""),
+ .contains("data-top-history-unchanged=\"false\""),
"{}",
page.serialize_html_async().await.unwrap()
);
diff --git a/moli-renderer-v8/src/context_bootstrap.rs b/moli-renderer-v8/src/context_bootstrap.rs
index eb7eacabd..35e6bb049 100644
--- a/moli-renderer-v8/src/context_bootstrap.rs
+++ b/moli-renderer-v8/src/context_bootstrap.rs
@@ -249,10 +249,7 @@ pub(crate) use self::file_api::{
};
pub(crate) use self::form_data_runtime::form_data_request_body;
use self::geometry_runtime::{build_dom_point_object, optional_dom_point_init_arg};
-pub(crate) use self::history_runtime::{
- increment_top_level_history_length_for_runtime_owner,
- set_top_level_history_length_at_least_for_runtime_owner,
-};
+pub(crate) use self::history_runtime::increment_top_level_history_length_for_runtime_owner;
pub(crate) use self::image_data::{
ImageDataClonePayload, build_image_data_object_from_clone_payload,
image_data_clone_payload_from_object,
diff --git a/moli-renderer-v8/src/context_bootstrap/history_runtime.rs b/moli-renderer-v8/src/context_bootstrap/history_runtime.rs
index 24957e362..8d9ec68bd 100644
--- a/moli-renderer-v8/src/context_bootstrap/history_runtime.rs
+++ b/moli-renderer-v8/src/context_bootstrap/history_runtime.rs
@@ -6,10 +6,7 @@ mod traversal;
pub(super) use self::admission::require_fully_active_history_owner;
pub(super) use self::apply::apply_history_entry;
-pub(crate) use self::length::{
- increment_top_level_history_length_for_runtime_owner,
- set_top_level_history_length_at_least_for_runtime_owner,
-};
+pub(crate) use self::length::increment_top_level_history_length_for_runtime_owner;
pub(super) use self::results::reject_pending_navigation_results;
pub(super) use self::traversal::{
apply_pending_history_traversal, cancel_active_history_traversal_intercept_settlement,
diff --git a/moli-renderer-v8/src/context_bootstrap/location_navigation.rs b/moli-renderer-v8/src/context_bootstrap/location_navigation.rs
index 7144dd196..100a9a6e7 100644
--- a/moli-renderer-v8/src/context_bootstrap/location_navigation.rs
+++ b/moli-renderer-v8/src/context_bootstrap/location_navigation.rs
@@ -304,7 +304,20 @@ fn navigate_location_object_with_source_element_and_child_navigate_event<'s>(
} else {
super::navigation_window::window_navigation_for_holder(scope, owner)
};
+ let child_handle = if runtime_window_is_global(scope, owner) {
+ None
+ } else {
+ child_browsing_context_handle_for_runtime_owner(scope, owner)
+ };
+ let replaces_initial_about_blank = child_handle.is_some_and(|handle| {
+ context_host_ptr_for_navigation_owner(scope, owner).is_some_and(|host_ptr| {
+ unsafe { &*host_ptr }.child_browsing_context_is_on_initial_about_blank_entry(handle)
+ })
+ });
let effective_kind = match kind {
+ LocationNavigationKind::Assign if replaces_initial_about_blank => {
+ LocationNavigationKind::Replace
+ }
LocationNavigationKind::Assign if source_element.is_some() && exact_same_href => {
LocationNavigationKind::Replace
}
@@ -402,11 +415,6 @@ fn navigate_location_object_with_source_element_and_child_navigate_event<'s>(
effective_kind,
);
}
- let child_handle = if runtime_window_is_global(scope, owner) {
- None
- } else {
- child_browsing_context_handle_for_runtime_owner(scope, owner)
- };
if let Some(host_ptr) = context_host_ptr_from_global_bridge(scope) {
let state = window_history_for_holder(scope, owner)
.map(|history| history_state_value(scope, history))
@@ -582,6 +590,17 @@ fn navigate_location_object_with_source_element_and_child_navigate_event<'s>(
if let Some(handle) = child_handle {
let is_javascript_url = resolved.scheme() == "javascript";
+ let host_ptr = context_host_ptr_for_navigation_owner(scope, owner);
+ let replaces_initial_empty_document = !is_javascript_url
+ && matches!(kind, LocationNavigationKind::Assign)
+ && host_ptr.is_some_and(|host_ptr| {
+ unsafe { &*host_ptr }.child_browsing_context_is_on_initial_about_blank_entry(handle)
+ });
+ let kind = if replaces_initial_empty_document {
+ LocationNavigationKind::Replace
+ } else {
+ kind
+ };
if (matches!(kind, LocationNavigationKind::Assign)
|| dispatch_child_navigate_event_for_all_kinds)
&& !is_javascript_url
@@ -607,7 +626,7 @@ fn navigate_location_object_with_source_element_and_child_navigate_event<'s>(
sync_location_object(scope, location, resolved.as_str());
apply_local_window_location_navigation(scope, owner, &resolved, kind);
}
- if let Some(host_ptr) = context_host_ptr_for_navigation_owner(scope, owner) {
+ if let Some(host_ptr) = host_ptr {
let host = unsafe { &mut *host_ptr };
if matches!(kind, LocationNavigationKind::Assign) && !is_javascript_url {
host.mark_child_browsing_context_top_level_history_increment(handle);
diff --git a/moli-renderer-v8/src/context_bootstrap/navigation_mutation/same_document.rs b/moli-renderer-v8/src/context_bootstrap/navigation_mutation/same_document.rs
index 2fb2fc86d..524ee9da2 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigation_mutation/same_document.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigation_mutation/same_document.rs
@@ -34,61 +34,37 @@ pub(in crate::context_bootstrap) fn update_navigation_current_entry_for_same_doc
let navigation_state_json =
navigation_state.and_then(|state| stringify_history_state(scope, state));
let entries = history_entries(scope, history).unwrap_or_else(|| v8::Array::new(scope, 0));
- let should_replace_initial_child_entry = matches!(kind, LocationNavigationKind::Assign)
- && !runtime_window_is_global(scope, owner)
- && current_navigation_index == 0
- && current_index > 0;
let mut pruned_entries = Vec::new();
match kind {
LocationNavigationKind::Assign => {
- if should_replace_initial_child_entry {
- let key = navigation_entry_key_value(scope, current_entry)
- .unwrap_or_else(|| new_navigation_entry_key().as_str().to_owned());
- let entry = create_navigation_entry(
- scope,
- href,
- history_state_json.as_deref(),
- navigation_state_json.as_deref(),
- None,
- current_navigation_index,
- &new_navigation_entry_id(),
- &key,
- );
- copy_navigation_entry_document_id(scope, current_entry, entry);
- let _ = entries.set_index(scope, current_index, entry.into());
- set_history_entries(scope, history, entries);
- set_history_state(scope, history, history_state);
- set_navigation_current_entry(scope, navigation, entry);
- } else {
- let next_index = current_index + 1;
- let next_navigation_index = current_navigation_index + 1;
- pruned_entries = pruned_history_entries(scope, entries, next_index);
- set_child_joint_top_index_for_entry(scope, owner, Some(current_entry));
- let next_entry = create_navigation_entry(
- scope,
- href,
- history_state_json.as_deref(),
- navigation_state_json.as_deref(),
- None,
- next_navigation_index,
- &new_navigation_entry_id(),
- &new_navigation_entry_key(),
- );
- copy_navigation_entry_document_id(scope, current_entry, next_entry);
- set_child_joint_top_index_for_entry(scope, owner, Some(next_entry));
- let next_entries = v8::Array::new(scope, (next_index + 1) as i32);
- for index in 0..next_index {
- if let Some(entry) = entries.get_index(scope, index) {
- let _ = next_entries.set_index(scope, index, entry);
- }
+ let next_index = current_index + 1;
+ let next_navigation_index = current_navigation_index + 1;
+ pruned_entries = pruned_history_entries(scope, entries, next_index);
+ set_child_joint_top_index_for_entry(scope, owner, Some(current_entry));
+ let next_entry = create_navigation_entry(
+ scope,
+ href,
+ history_state_json.as_deref(),
+ navigation_state_json.as_deref(),
+ None,
+ next_navigation_index,
+ &new_navigation_entry_id(),
+ &new_navigation_entry_key(),
+ );
+ copy_navigation_entry_document_id(scope, current_entry, next_entry);
+ set_child_joint_top_index_for_entry(scope, owner, Some(next_entry));
+ let next_entries = v8::Array::new(scope, (next_index + 1) as i32);
+ for index in 0..next_index {
+ if let Some(entry) = entries.get_index(scope, index) {
+ let _ = next_entries.set_index(scope, index, entry);
}
- let _ = next_entries.set_index(scope, next_index, next_entry.into());
- set_history_entries(scope, history, next_entries);
- set_history_index(scope, history, next_index);
- set_history_length_at_least_visible_entries(scope, history, next_entries);
- set_history_state(scope, history, history_state);
- set_navigation_current_entry(scope, navigation, next_entry);
}
+ let _ = next_entries.set_index(scope, next_index, next_entry.into());
+ set_history_entries(scope, history, next_entries);
+ set_history_index(scope, history, next_index);
+ set_history_length_at_least_visible_entries(scope, history, next_entries);
+ set_history_state(scope, history, history_state);
+ set_navigation_current_entry(scope, navigation, next_entry);
}
LocationNavigationKind::Replace => {
let key = navigation_entry_key_value(scope, current_entry)
diff --git a/moli-renderer-v8/src/context_bootstrap/navigation_projection.rs b/moli-renderer-v8/src/context_bootstrap/navigation_projection.rs
index 187381cdd..1598fe068 100644
--- a/moli-renderer-v8/src/context_bootstrap/navigation_projection.rs
+++ b/moli-renderer-v8/src/context_bootstrap/navigation_projection.rs
@@ -260,18 +260,15 @@ fn history_length_floor_from_visible_entries<'s>(
return visible_length;
}
- // A child sees the joint session-history length. The primary top-level
- // runtime keeps one hidden initial about:blank predecessor, while a
- // lightweight popup's first navigation replaces its initial empty entry.
- // Project the offset of the owning root instead of assuming every child
- // belongs to the primary top-level runtime.
+ // A child sees the joint session-history length. Creating its initial
+ // entry does not add a new joint-history step, so start from the current
+ // top-level length and only grow it when the child gains a visible entry.
let top_owner = runtime_top_window_owner(scope, owner);
- let root_predecessor_offset = if runtime_window_is_global(scope, top_owner) {
- 1.0
- } else {
- 0.0
- };
- visible_length + root_predecessor_offset
+ let top_length = window_history_for_holder(scope, top_owner)
+ .and_then(|history| history_length_number(scope, history))
+ .unwrap_or(visible_length)
+ .max(0.0);
+ visible_length.max(top_length)
}
fn set_top_history_length_at_least<'s>(
diff --git a/moli-renderer-v8/src/document_runtime/mutation_commands.rs b/moli-renderer-v8/src/document_runtime/mutation_commands.rs
index 13ce9879e..4e64ad31a 100644
--- a/moli-renderer-v8/src/document_runtime/mutation_commands.rs
+++ b/moli-renderer-v8/src/document_runtime/mutation_commands.rs
@@ -725,7 +725,7 @@ impl DocumentRuntime {
if is_srcdoc {
runtime.clear_child_browsing_context_cached_snapshot_for_navigation(handle);
}
- runtime.refresh_child_browsing_context_and_initial_history_floor(scope, handle);
+ runtime.refresh_child_browsing_context_and_queue_ready_work(scope, handle);
if is_srcdoc {
runtime.sync_existing_child_browsing_context_window_state(scope, handle);
} else if is_navigation_attribute
diff --git a/moli-renderer-v8/src/document_runtime/mutation_commands/tree/context_followups.rs b/moli-renderer-v8/src/document_runtime/mutation_commands/tree/context_followups.rs
index 46f3460b7..2e653ac11 100644
--- a/moli-renderer-v8/src/document_runtime/mutation_commands/tree/context_followups.rs
+++ b/moli-renderer-v8/src/document_runtime/mutation_commands/tree/context_followups.rs
@@ -20,7 +20,7 @@ impl DocumentRuntime {
for &root in insertion_plan.insertion_roots {
runtime.clear_disconnected_shadow_roots_in_subtree(root);
runtime.drop_child_browsing_contexts_moved_into_own_document_subtree(scope, root);
- runtime.sync_child_browsing_context_subtree_and_initial_history_floor(scope, root);
+ runtime.sync_child_browsing_context_subtree(scope, root);
}
}
diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commands.rs b/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commands.rs
index d2908a851..a64331550 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commands.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/child_frame_navigation/commands.rs
@@ -22,8 +22,14 @@ impl JsContextHost {
handle,
"The navigation was canceled.".to_owned(),
);
+ let replace_initial_empty_document =
+ self.child_browsing_context_is_on_initial_about_blank_entry(handle);
if let Some(entry) = self.child_browsing_contexts.get_mut(&handle) {
- entry.apply_navigation_to_entry_seed(&url);
+ if replace_initial_empty_document {
+ entry.replace_navigation_in_entry_seed(&url);
+ } else {
+ entry.apply_navigation_to_entry_seed(&url);
+ }
}
self.sync_existing_child_browsing_context_runtime_surface_from_seed(scope, handle);
self.queue_child_browsing_context_navigation_to_url(handle, &url)
@@ -38,8 +44,14 @@ impl JsContextHost {
if !self.child_browsing_contexts.contains_key(&handle) {
return false;
}
+ let replace_initial_empty_document =
+ self.child_browsing_context_is_on_initial_about_blank_entry(handle);
if let Some(entry) = self.child_browsing_contexts.get_mut(&handle) {
- entry.apply_navigation_to_entry_seed(&request.url);
+ if replace_initial_empty_document {
+ entry.replace_navigation_in_entry_seed(&request.url);
+ } else {
+ entry.apply_navigation_to_entry_seed(&request.url);
+ }
}
self.sync_existing_child_browsing_context_runtime_surface_from_seed(scope, handle);
self.queue_child_browsing_context_navigation_request(handle, request)
diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_frames.rs b/moli-renderer-v8/src/native_bridge/context_host/child_frames.rs
index 5cb2034e7..908f556fe 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/child_frames.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/child_frames.rs
@@ -5,7 +5,6 @@ use super::{
child_documents::CompletedFrameOwnerResourceTiming,
};
use crate::{
- context_bootstrap::set_top_level_history_length_at_least_for_runtime_owner,
document_runtime::{DocumentPolicyContainer, DocumentSandboxPolicy, DomHandle},
frame_owner_model::{
ChildFrameOwnerSnapshot, FrameDocumentTaskOwner, FrameId, FrameRealmId, FrameScriptJob,
@@ -743,7 +742,8 @@ impl ChildBrowsingContextEntry {
pub(super) fn navigation_seed_is_initial_about_blank_commit(&self) -> bool {
self.navigation_entry_seed.current_index == 0
&& self.navigation_entry_seed.entries.len() == 1
- && self.navigation_entry_seed.entries[0].url == "about:blank"
+ && Url::parse(&self.navigation_entry_seed.entries[0].url)
+ .is_ok_and(|url| moli_url::is_about_blank(&url))
}
pub(super) fn navigation_seed_is_initial_attribute_target(&self, url: &Url) -> bool {
diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_frames/lookup.rs b/moli-renderer-v8/src/native_bridge/context_host/child_frames/lookup.rs
index b8a11c904..2e4ac8739 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/child_frames/lookup.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/child_frames/lookup.rs
@@ -13,34 +13,25 @@ impl JsContextHost {
.is_some_and(ChildBrowsingContextEntry::has_cached_snapshot)
}
- pub(crate) fn sync_initial_child_browsing_context_history_floor(
- &self,
- scope: &mut v8::PinScope<'_, '_>,
- ) {
- let main_document_child_count = self
- .top_level_child_browsing_context_handles_in_frame_tree_order()
- .into_iter()
- .filter(|handle| {
- self.child_browsing_context_popup_owner_id(*handle)
- .is_none()
- })
- .count();
- if main_document_child_count == 0 {
- return;
- }
- let owner = scope.get_current_context().global(scope);
- set_top_level_history_length_at_least_for_runtime_owner(
- scope,
- owner,
- 1.0 + main_document_child_count as f64,
- );
- }
-
pub(crate) fn child_browsing_context_count(&self) -> usize {
self.top_level_child_browsing_context_handles_in_frame_tree_order()
.len()
}
+ pub(crate) fn child_browsing_context_is_on_initial_about_blank_entry(
+ &self,
+ handle: DomHandle,
+ ) -> bool {
+ let seed_is_initial_about_blank = self
+ .child_browsing_contexts
+ .get(&handle)
+ .is_some_and(ChildBrowsingContextEntry::navigation_seed_is_initial_about_blank_commit);
+ seed_is_initial_about_blank
+ && self
+ .child_browsing_context_current_url(handle)
+ .is_some_and(|url| moli_url::is_about_blank(&url))
+ }
+
pub(crate) fn child_browsing_context_handles_in_document_order(&self) -> Vec<DomHandle> {
let mut handles = Vec::new();
self.collect_child_browsing_context_handles_in_document_order_from_document(
diff --git a/moli-renderer-v8/src/native_bridge/context_host/child_frames/registry.rs b/moli-renderer-v8/src/native_bridge/context_host/child_frames/registry.rs
index 5db5916d5..a36c85b83 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/child_frames/registry.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/child_frames/registry.rs
@@ -595,16 +595,6 @@ impl JsContextHost {
had_handles
}
- pub(crate) fn sync_child_browsing_context_subtree_and_initial_history_floor(
- &mut self,
- scope: &mut v8::PinScope<'_, '_>,
- root: DomHandle,
- ) {
- if self.sync_child_browsing_context_subtree(scope, root) {
- self.sync_initial_child_browsing_context_history_floor(scope);
- }
- }
-
pub(crate) fn drop_child_browsing_context_subtree(&mut self, root: DomHandle) {
let mut handles = Vec::new();
self.collect_child_browsing_context_host_handles(root, &mut handles);
@@ -808,7 +798,7 @@ impl JsContextHost {
.collect()
}
- pub(crate) fn refresh_child_browsing_context_and_initial_history_floor(
+ pub(crate) fn refresh_child_browsing_context_and_queue_ready_work(
&mut self,
scope: &mut v8::PinScope<'_, '_>,
handle: DomHandle,
@@ -816,7 +806,6 @@ impl JsContextHost {
if let Some(work) = self.refresh_child_browsing_context(scope, handle) {
self.push_child_document_script_ready_input(work);
}
- self.sync_initial_child_browsing_context_history_floor(scope);
}
}
diff --git a/moli-renderer-v8/src/native_bridge/element/url_attributes/iframe.rs b/moli-renderer-v8/src/native_bridge/element/url_attributes/iframe.rs
index 80b9393cd..4d06707c7 100644
--- a/moli-renderer-v8/src/native_bridge/element/url_attributes/iframe.rs
+++ b/moli-renderer-v8/src/native_bridge/element/url_attributes/iframe.rs
@@ -38,10 +38,12 @@ pub(in crate::native_bridge) fn update_iframe_snapshot_navigation(
handle,
previous_seed_snapshot,
);
+ let replace_current =
+ runtime.child_browsing_context_is_on_initial_about_blank_entry(handle);
if runtime.queue_child_browsing_context_navigation_from_existing_seed(
handle,
&navigation_target,
- false,
+ replace_current,
) {
return;
}
diff --git a/moli-renderer-v8/src/script_vm/child_host_load.rs b/moli-renderer-v8/src/script_vm/child_host_load.rs
index dfd4db83f..5b07ac29e 100644
--- a/moli-renderer-v8/src/script_vm/child_host_load.rs
+++ b/moli-renderer-v8/src/script_vm/child_host_load.rs
@@ -27,9 +27,6 @@ impl<'vm> ChildHostLoadOwner<'vm> {
let ready_work = context_host
.borrow_mut()
.resync_child_browsing_contexts_into_ready_work(scope);
- context_host
- .borrow()
- .sync_initial_child_browsing_context_history_floor(scope);
Ok(ready_work)
}) else {
return;
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs
index bae007532..f8b1dd90a 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_elements/dom_surface.rs
@@ -10400,7 +10400,7 @@ async fn top_history_back_routes_to_child_joint_history_entry() {
assert_eq!(
setup,
- "https://joint-child-back.test/page.html|3|3|https://joint-child-back.test/page.html#child"
+ "https://joint-child-back.test/page.html|2|2|https://joint-child-back.test/page.html#child"
);
let _ = vm
.run_one_oldest_ready_page_task_executor_turn(&loader)
@@ -10482,7 +10482,7 @@ async fn top_history_back_ignores_removed_child_joint_history_entry() {
assert_eq!(
setup,
- "https://removed-child-joint-back.test/page.html|1|0|3|3|https://removed-child-joint-back.test/page.html#child"
+ "https://removed-child-joint-back.test/page.html|1|0|2|2|https://removed-child-joint-back.test/page.html#child"
);
vm.eval("document.querySelector('iframe').remove(); history.back(); 'queued'")
@@ -10504,7 +10504,7 @@ async fn top_history_back_ignores_removed_child_joint_history_entry() {
assert_eq!(
result,
- "https://removed-child-joint-back.test/page.html|1|0|3|true"
+ "https://removed-child-joint-back.test/page.html|1|0|2|true"
);
}
@@ -10552,7 +10552,7 @@ async fn child_cross_document_pending_navigation_exposes_back_availability() {
assert_eq!(
state,
- "about:srcdoc|2|0:about:srcdoc|0:about:srcdoc|true|false"
+ "about:srcdoc|1|0:about:srcdoc|0:about:srcdoc|true|false"
);
}
#[tokio::test]
diff --git a/moli-wpt-compat/fixtures/wpt/ported/navigation/navigation-child-browsing-context-push-result-surface-basic.html b/moli-wpt-compat/fixtures/wpt/ported/navigation/navigation-child-browsing-context-push-result-surface-basic.html
index f6a565b32..78fd0751b 100644
--- a/moli-wpt-compat/fixtures/wpt/ported/navigation/navigation-child-browsing-context-push-result-surface-basic.html
+++ b/moli-wpt-compat/fixtures/wpt/ported/navigation/navigation-child-browsing-context-push-result-surface-basic.html
@@ -75,7 +75,7 @@ promise_test(async function () {
);
assert_equals(
sync,
- "hash=#dest|len=3|committed=false|finished=false|history=null|entry={\"step\":7}|listener=1|property=1|from=" +
+ "hash=#dest|len=2|committed=false|finished=false|history=null|entry={\"step\":7}|listener=1|property=1|from=" +
childUrl +
"|propertyFrom=" +
childUrl +
@@ -86,7 +86,7 @@ promise_test(async function () {
);
assert_equals(
timeout,
- "hash=#dest|len=3|committed=true|finished=true|history=null|entry={\"step\":7}|listener=1|property=1|from=" +
+ "hash=#dest|len=2|committed=true|finished=true|history=null|entry={\"step\":7}|listener=1|property=1|from=" +
childUrl +
"|propertyFrom=" +
childUrl +
diff --git a/moli-wpt-compat/fixtures/wpt/ported/navigation/navigation-child-browsing-context-replace-result-surface-basic.html b/moli-wpt-compat/fixtures/wpt/ported/navigation/navigation-child-browsing-context-replace-result-surface-basic.html
index 14a415b2d..ea3d2328e 100644
--- a/moli-wpt-compat/fixtures/wpt/ported/navigation/navigation-child-browsing-context-replace-result-surface-basic.html
+++ b/moli-wpt-compat/fixtures/wpt/ported/navigation/navigation-child-browsing-context-replace-result-surface-basic.html
@@ -75,7 +75,7 @@ promise_test(async function () {
);
assert_equals(
sync,
- "hash=#dest|len=2|committed=false|finished=false|history=null|entry={\"step\":9}|listener=1|property=1|from=" +
+ "hash=#dest|len=1|committed=false|finished=false|history=null|entry={\"step\":9}|listener=1|property=1|from=" +
childUrl +
"|propertyFrom=" +
childUrl +
@@ -86,7 +86,7 @@ promise_test(async function () {
);
assert_equals(
timeout,
- "hash=#dest|len=2|committed=true|finished=true|history=null|entry={\"step\":9}|listener=1|property=1|from=" +
+ "hash=#dest|len=1|committed=true|finished=true|history=null|entry={\"step\":9}|listener=1|property=1|from=" +
childUrl +
"|propertyFrom=" +
childUrl +