Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(popups): require a fragment for same-document navigation

ldm0bec83877294c
diff --git a/moli-renderer-v8/src/native_bridge/context_host/popups.rs b/moli-renderer-v8/src/native_bridge/context_host/popups.rs
index 78806be27..5204a4d92 100644
--- a/moli-renderer-v8/src/native_bridge/context_host/popups.rs
+++ b/moli-renderer-v8/src/native_bridge/context_host/popups.rs
@@ -1496,11 +1496,13 @@ impl JsContextHost {
let current_url = lightweight_popup_location_href(scope, window)
.or_else(|| self.lightweight_popup_location_url(popup_id));
let target_url = request.url.clone();
- if request.method == "GET"
+ let allows_fragment_navigation = request.method == "GET"
+ && target_url.fragment().is_some()
&& !matches!(
kind,
crate::context_bootstrap::LocationNavigationKind::Reload
- )
+ );
+ if allows_fragment_navigation
&& urls_refer_to_same_document_except_fragment(current_url.as_ref(), &target_url)
{
let previous_url = current_url.clone();
@@ -1530,11 +1532,7 @@ impl JsContextHost {
}
return true;
}
- if request.method == "GET"
- && !matches!(
- kind,
- crate::context_bootstrap::LocationNavigationKind::Reload
- )
+ if allows_fragment_navigation
&& let Some(previous_url) =
self.pending_lightweight_popup_same_document_previous_url(popup_id, &target_url)
{
diff --git a/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms/wrappers.rs b/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms/wrappers.rs
index 917dd3b9c..ed454f7dd 100644
--- a/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms/wrappers.rs
+++ b/moli-renderer-v8/src/script_vm/tests/dom_xhr/forms/wrappers.rs
@@ -135,9 +135,14 @@ async fn assert_lightweight_popup_form_submission(method: &str) {
("_parent", "form.submit()"),
("_top", "form.requestSubmit()"),
];
- // POST to the current URL must still fetch a new document on every submit.
- let submissions = if method == "post" { 2 } else { 1 };
- let server = StaticHttpServer::spawn(cases.len() * submissions).await;
+ // Submitting to the current URL must still load a new document every time.
+ let submissions = 2;
+ let server = StaticHttpServer::spawn_with_responder(
+ cases.len() * submissions,
+ "Content-Type: text/html; charset=utf-8\r\nCache-Control: no-store\r\n",
+ |_, _| "<!doctype html><body>child fixture</body>".to_owned(),
+ )
+ .await;
let loader = static_http_loader([]);
let opener_url = server.base_url().join("opener.html").unwrap();
let expected_target = if method == "get" {
diff --git a/moli-renderer-v8/src/script_vm/tests/http_fixture.rs b/moli-renderer-v8/src/script_vm/tests/http_fixture.rs
index 97b193939..46d676bf2 100644
--- a/moli-renderer-v8/src/script_vm/tests/http_fixture.rs
+++ b/moli-renderer-v8/src/script_vm/tests/http_fixture.rs
@@ -59,7 +59,7 @@ impl StaticHttpServer {
.await
}
- async fn spawn_with_responder(
+ pub(super) async fn spawn_with_responder(
expected_requests: usize,
response_headers: &'static str,
response_body: impl Fn(usize, &CapturedHttpRequest) -> String + Send + 'static,