Skip to content

armgit / moli

Public Imported from GitHub
0

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

fix(cdp): complete Fetch configuration updates during navigation

ldm06c0e8caebcde
diff --git a/moli-protocol/src/domains/fetch.rs b/moli-protocol/src/domains/fetch.rs
index cdf511fb5..0f1003a27 100644
--- a/moli-protocol/src/domains/fetch.rs
+++ b/moli-protocol/src/domains/fetch.rs
@@ -882,7 +882,9 @@ fn complete_fetch_config_update_command(
Ok(completion) => completion,
Err(error) => return CommandOutputPlan::error(-32000, error),
};
- let page = match conn.loaded_page_mut_for_protocol_access_for_owner(&owner_scope) {
+ // Fetch policy belongs to the target and may finish updating while a
+ // navigation is replacing its document.
+ let page = match conn.loaded_page_mut_for_target_configuration_for_owner(&owner_scope) {
Ok(page) => page,
Err(message) if message == "NoDocumentLoaded" => {
return CommandOutputPlan::from_devtools_result(result);
diff --git a/moli-protocol/src/domains/fetch/tests/navigation_subresource.rs b/moli-protocol/src/domains/fetch/tests/navigation_subresource.rs
index df378364c..878644f27 100644
--- a/moli-protocol/src/domains/fetch/tests/navigation_subresource.rs
+++ b/moli-protocol/src/domains/fetch/tests/navigation_subresource.rs
@@ -111,7 +111,7 @@ async fn request_stage_navigation_request_paused_includes_synthesized_cookie_hea
}
#[tokio::test(flavor = "multi_thread")]
-async fn fetch_enable_persists_subresource_interception_across_navigation() {
+async fn fetch_enable_during_paused_navigation_persists_subresource_interception() {
async fn page() -> impl IntoResponse {
(
[(CONTENT_TYPE.as_str(), "text/html")],
@@ -152,6 +152,13 @@ fetch('/api', { method: 'POST', body: 'nav-payload' })
.runtime_slot
.enable_primary_network_events();
ctx.conn.install_browser_context_fixture_for_test(bc);
+ ctx.install_navigation_fixture_for_session_owner("about:blank", Some("SID-1"))
+ .await;
+ wait_until_message(&mut ctx, "SID-1", "initial document load", |message| {
+ message["method"] == json!("Page.loadEventFired")
+ })
+ .await;
+ ctx.sent.clear();
let page_url = format!("http://{addr}/page");
let api_url = format!("http://{addr}/api");
@@ -179,6 +186,19 @@ fetch('/api', { method: 'POST', body: 'nav-payload' })
.expect("main document request id")
.to_owned();
+ // Updating target configuration must preserve the held document request
+ // and apply to the subresources loaded by its replacement document.
+ ctx.process_async(json!({
+ "id": 73_001,
+ "method": "Fetch.enable",
+ "sessionId": "SID-1",
+ "params": {
+ "patterns": [{ "urlPattern": "*api", "resourceType": "Fetch" }]
+ }
+ }))
+ .await;
+ ctx.expect_result(73_001, json!({}), Some("SID-1"));
+
ctx.process_async(json!({
"id": 75,
"method": "Fetch.continueRequest",
@@ -231,7 +251,7 @@ fetch('/api', { method: 'POST', body: 'nav-payload' })
.expect("navigate result");
assert_eq!(
navigate_result["result"],
- json!({ "frameId": "TID-1", "loaderId": LOADER_ID })
+ json!({ "frameId": "TID-1", "loaderId": main_document_paused["params"]["networkId"] })
);
let initial_subresource_request = ctx
.sent