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(cdp): abort no-content navigations before document preparation
ldm05b7984973fd9
diff --git a/moli-cdp-smoke/README.md b/moli-cdp-smoke/README.mdindex d2ef73501..7c59d0051 100644--- a/moli-cdp-smoke/README.md+++ b/moli-cdp-smoke/README.md@@ -161,14 +161,22 @@ The `navigation-outcomes` group was calibrated on 2026-08-23 against Debiandirectly drives `Page.navigate` and correlates the result with the matchingDocument request/response identity. The matrix covers text, renderable HTML,empty, redirected, and HTTP-error attachments; unsupported binary MIME; an-ordinary HTML 502 document; 204 No Content; and a reset before response+ordinary HTML 502 document; 204 No Content; 205 Reset Content; and a reset before responseheaders. Chromium reports successful attachments as `isDownload=true` plus`net::ERR_ABORTED` while retaining the old Document, but a 204 reports the sameerror with `isDownload=false`; the smoke therefore treats `isDownload`, not the-error string, as authoritative. Moli currently commits binary responses and-204 responses as external Documents where Chromium retains the old Document;-those two cases assert internally coherent response/lifecycle evidence and-record the engine-selected outcome rather than claiming parity. For a 404+error string, as authoritative. The 204/205 matrix was expanded on 2026-10-02+against the same executable. Eight raw CDP probes cover ordinary responses,+attachments, request-stage `Fetch.fulfillRequest`, and response-stage+`Fetch.continueResponse`. The expanded group was also run unchanged against+Chromium three times. Ordinary and intercepted 204/205 responses retain the+Document, realm, form values, and navigation history, emit exactly one matching+`Network.loadingFailed` with `net::ERR_ABORTED` and `canceled=true`, and never+emit DOMContentLoaded for the attempted loader. Attachments retain+`isDownload=true` even with status 204/205. Moli still commits binary responses+as external Documents where Chromium retains the old Document; that case+asserts internally coherent response/lifecycle evidence and records the+engine-selected outcome rather than claiming parity. For a 404attachment, both engines preserve `isDownload` and the HTTP response evidence,while Chromium commits an error Document with `net::ERR_INVALID_RESPONSE` andMoli retains the prior Document with `net::ERR_ABORTED`; that difference isdiff --git a/moli-cdp-smoke/moli_cdp_smoke/fixture.py b/moli-cdp-smoke/moli_cdp_smoke/fixture.pyindex 1aa52bae4..f49f13720 100644--- a/moli-cdp-smoke/moli_cdp_smoke/fixture.py+++ b/moli-cdp-smoke/moli_cdp_smoke/fixture.py@@ -1638,11 +1638,23 @@ class FixtureServer:"text/html; charset=utf-8",b"<!doctype html><title>gateway error</title><main>gateway error</main>",)- elif route == "/navigation-no-content":+ elif route == "/navigation-empty":+ self._send_common(HTTPStatus.OK, "text/plain; charset=utf-8", b"")+ elif route in {+ "/navigation-no-content",+ "/navigation-reset-content",+ "/navigation-no-content-attachment",+ "/navigation-reset-content-attachment",+ }:self._send_common(- HTTPStatus.NO_CONTENT,+ HTTPStatus.RESET_CONTENT if "reset" in route else HTTPStatus.NO_CONTENT,"text/plain; charset=utf-8",b"",+ headers=(+ {"Content-Disposition": 'attachment; filename="empty.txt"'}+ if route.endswith("-attachment")+ else None+ ),)elif route == "/slow-download":self._send_slow_download()diff --git a/moli-cdp-smoke/moli_cdp_smoke/groups/navigation_outcomes.py b/moli-cdp-smoke/moli_cdp_smoke/groups/navigation_outcomes.pyindex b49e50e22..4b668021c 100644--- a/moli-cdp-smoke/moli_cdp_smoke/groups/navigation_outcomes.py+++ b/moli-cdp-smoke/moli_cdp_smoke/groups/navigation_outcomes.py@@ -1,7 +1,9 @@from __future__ import annotations+import asynciofrom contextlib import asynccontextmanager, suppressfrom dataclasses import dataclass+from functools import partialfrom typing import Any, AsyncIterator, Awaitable, Callablefrom ..assertions import SmokeError, assert_equal, record_contract, wait_until@@ -104,10 +106,33 @@ def _contracts() -> tuple[NavigationOutcomeContract, ...]:"An ordinary HTML HTTP error is a successful navigation with status evidence and a DOMContentLoaded Document, not a Page.navigate network error.",_http_error_document,),- NavigationOutcomeContract(- "navigate_no_content_is_not_download",- "A 204 response is never inferred to be a download merely because Chromium reports net::ERR_ABORTED.",- _no_content,+ *(+ NavigationOutcomeContract(+ name,+ f"A {status} response reports net::ERR_ABORTED without a download or a new Document, including Fetch interception.",+ partial(_no_content, status=status, fetch_stage=stage),+ )+ for name, status, stage in (+ ("navigate_no_content_is_not_download", 204, None),+ ("navigate_reset_content_retains_document", 205, None),+ ("navigate_fulfilled_no_content_retains_document", 204, "Request"),+ ("navigate_fulfilled_reset_content_retains_document", 205, "Request"),+ ("navigate_overridden_no_content_retains_document", 204, "Response"),+ ("navigate_overridden_reset_content_retains_document", 205, "Response"),+ )+ ),+ *(+ NavigationOutcomeContract(+ f"navigate_{name.replace('-', '_')}_attachment_is_download",+ f"An attachment remains a download even when its response status is {status}.",+ partial(+ _successful_download,+ route=f"/navigation-{name}-attachment",+ expected_mime="text/plain",+ expected_status=status,+ ),+ )+ for name, status in (("no-content", 204), ("reset-content", 205))),NavigationOutcomeContract("navigate_transport_failure_is_not_download",@@ -127,7 +152,9 @@ async def _new_probe(state: SmokeState) -> AsyncIterator[NavigationProbe]:"Network.requestWillBeSent","Network.responseReceived","Network.loadingFailed",+ "Network.loadingFinished","Page.lifecycleEvent",+ "Runtime.executionContextsCleared",],)try:@@ -178,13 +205,14 @@ async def _successful_download(*,route: str,expected_mime: str,+ expected_status: int = 200,) -> dict[str, Any]:async with _new_probe(state) as probe:url = f"{state.fixture}{route}"result = await probe.cdp.send("Page.navigate", {"url": url})_assert_download_result(result, "net::ERR_ABORTED")response_event = await _wait_for_document_response(probe, url)- _assert_response(response_event, status=200, mime=expected_mime, url=url)+ _assert_response(response_event, status=expected_status, mime=expected_mime, url=url)_assert_request_response_identity(probe.events, response_event, url)snapshot = await _active_document_snapshot(probe.cdp)_assert_retained_document(snapshot)@@ -285,25 +313,99 @@ async def _http_error_document(state: SmokeState) -> dict[str, Any]:return _compact_observation(result, response_event, snapshot)-async def _no_content(state: SmokeState) -> dict[str, Any]:+async def _no_content(+ state: SmokeState,+ *,+ status: int,+ fetch_stage: str | None,+) -> dict[str, Any]:async with _new_probe(state) as probe:- url = f"{state.fixture}/navigation-no-content"- result = await probe.cdp.send("Page.navigate", {"url": url})- if result.get("isDownload") is True:- raise SmokeError(f"204 response was misreported as a download: {result}")+ route = "/navigation-no-content" if status == 204 else "/navigation-reset-content"+ if fetch_stage == "Response":+ route = f"/navigation-empty?no-content-override={status}"+ url = f"{state.fixture}{route}"+ await _evaluate_value(+ probe.cdp,+ "document.body.innerHTML='<input id=retainedField value=retained>';",+ )+ history = await probe.cdp.send("Page.getNavigationHistory")+ if fetch_stage is None:+ result = await probe.cdp.send("Page.navigate", {"url": url})+ else:+ paused = asyncio.get_running_loop().create_future()+ probe.cdp.once("Fetch.requestPaused", lambda params: paused.set_result(params))+ await probe.cdp.send(+ "Fetch.enable",+ {"patterns": [{"urlPattern": url, "requestStage": fetch_stage}]},+ )+ navigation = asyncio.create_task(probe.cdp.send("Page.navigate", {"url": url}))+ try:+ request = await paused+ headers = [{"name": "Content-Type", "value": "text/plain; charset=utf-8"}]+ if fetch_stage == "Request":+ await probe.cdp.send(+ "Fetch.fulfillRequest",+ {+ "requestId": request["requestId"],+ "responseCode": status,+ "responseHeaders": headers,+ "body": "",+ },+ )+ else:+ await probe.cdp.send(+ "Fetch.continueResponse",+ {+ "requestId": request["requestId"],+ "responseCode": status,+ "responsePhrase": "No Content" if status == 204 else "Reset Content",+ "responseHeaders": headers,+ },+ )+ result = await navigation+ finally:+ if not navigation.done():+ navigation.cancel()+ with suppress(asyncio.CancelledError):+ await navigation+ assert_equal(result.get("isDownload"), False, f"{status} isDownload")+ assert_equal(result.get("errorText"), "net::ERR_ABORTED", f"{status} navigation errorText")response_event = await _wait_for_document_response(probe, url)- _assert_response(response_event, status=204, mime="text/plain", url=url)+ _assert_response(response_event, status=status, mime="text/plain", url=url)+ _assert_request_response_identity(probe.events, response_event, url)+ await wait_until(+ lambda: _loading_failure_for_url(probe.events, url) is not None,+ f"{status} main-document Network.loadingFailed",+ )+ failure = _loading_failure_for_url(probe.events, url)+ if failure is None:+ raise SmokeError(f"missing {status} main-document Network.loadingFailed")+ assert_equal(+ failure["params"].get("errorText"), "net::ERR_ABORTED", f"{status} Network errorText"+ )+ assert_equal(failure["params"].get("canceled"), True, f"{status} canceled navigation")+ request_id = response_event["params"]["requestId"]+ terminals = [+ event+ for event in probe.events+ if event["method"] in {"Network.loadingFailed", "Network.loadingFinished"}+ and event["params"].get("requestId") == request_id+ ]+ assert_equal(len(terminals), 1, f"{status} navigation terminal count")snapshot = await _active_document_snapshot(probe.cdp)- error_text = result.get("errorText")- if error_text:- assert_equal(error_text, "net::ERR_ABORTED", "204 navigation errorText")- _assert_retained_document(snapshot)- outcome = "retained-document"- else:- assert_equal(snapshot.get("href"), url, "204 committed Document URL")- outcome = "committed-document"+ _assert_retained_document(snapshot)+ _assert_no_navigation_dcl(probe.events, response_event)+ if any(event["method"] == "Runtime.executionContextsCleared" for event in probe.events):+ raise SmokeError(f"{status} cleared the retained Document's Runtime contexts")+ assert_equal(+ await _evaluate_value(probe.cdp, "document.querySelector('#retainedField')?.value"),+ "retained",+ f"{status} retained form value",+ )+ assert_equal(await probe.cdp.send("Page.getNavigationHistory"), history, f"{status} history")observed = _compact_observation(result, response_event, snapshot)- observed["outcome"] = outcome+ observed["outcome"] = "retained-document"+ observed["fetchStage"] = fetch_stagereturn observed@@ -445,7 +547,7 @@ def _assert_no_navigation_dcl(in {"DOMContentLoaded", "domContentLoaded"}]if matching:- raise SmokeError(f"download navigation emitted DOMContentLoaded: {matching}")+ raise SmokeError(f"non-document navigation emitted DOMContentLoaded: {matching}")def _document_request_events(events: list[dict[str, Any]]) -> list[dict[str, Any]]:diff --git a/moli-protocol/src/conn.rs b/moli-protocol/src/conn.rsindex 59bf56372..d970b6d16 100644--- a/moli-protocol/src/conn.rs+++ b/moli-protocol/src/conn.rs@@ -582,8 +582,8 @@ pub use state::{DownloadNavigation, EmulatedDeviceMetrics, EmulatedGeolocationOverride,EmulatedGeolocationOverrideState, EmulatedMediaOverrides, IsolatedWorldDefinition,LoadedNavigation, NavigationDispatchState, NavigationLoadOutcome, NavigationRequestLoadPolicy,- PageNavigationHistoryEntry, PageTargetHost, PendingNavigationHistoryUpdate,- RuntimeBindingDefinition, TargetInfo, URL_BASE,+ NoContentNavigation, PageNavigationHistoryEntry, PageTargetHost,+ PendingNavigationHistoryUpdate, RuntimeBindingDefinition, TargetInfo, URL_BASE,};#[cfg(test)]pub(crate) use state::{diff --git a/moli-protocol/src/conn/runtime_load.rs b/moli-protocol/src/conn/runtime_load.rsindex f2d1b7aa2..c69d2b1c0 100644--- a/moli-protocol/src/conn/runtime_load.rs+++ b/moli-protocol/src/conn/runtime_load.rs@@ -32,6 +32,10 @@ use crate::domains::network::{const HTTP_RESPONSE_CODE_FAILURE_ERROR_TEXT: &str = "net::ERR_HTTP_RESPONSE_CODE_FAILURE";const CAPTURED_RAW_REPLAY_CHUNK_SIZE: usize = 64 * 1024;+fn response_status_has_no_content(status: u16) -> bool {+ matches!(status, 204 | 205)+}+fn apply_navigation_request_load_policy(load_inputs: TargetNavigationLoadInputs,policy: NavigationRequestLoadPolicy,@@ -891,6 +895,7 @@ impl BackgroundNavigationLoadJob {response_status_may_use_http_error_page(response.status);if !super::downloads::response_headers_indicate_download(&response.headers)&& !defer_early_result_for_http_error_body+ && !response_status_has_no_content(response.status)&& let Some(early_result) = early_result.take(){early_result_sent = early_result.emit();@@ -1269,6 +1274,14 @@ async fn build_navigation_from_streaming_raw_response_with_engine_async(}let body_network_progress_state =body_progress_source.body_network_progress_for_completed_events(network_events);+ if response_status_has_no_content(response_status) {+ return Ok(NavigationLoadOutcome::NoContent(Box::new(+ NoContentNavigation {+ final_url,+ network_progress: body_network_progress_state,+ },+ )));+ }let body_progress_source_for_body_finish = body_progress_source.clone();let initial_body_chunk = if response_status_may_use_http_error_page(response_status) {match first_nonempty_response_body_chunk(&mut response).await? {@@ -2000,6 +2013,9 @@ impl CdpConnection {NavigationLoadOutcome::Download(_) => {Err(anyhow::anyhow!("navigation resolved to a download"))}+ NavigationLoadOutcome::NoContent(_) => {+ Err(anyhow::Error::msg(moli_fetch::NET_ERR_ABORTED_ERROR_TEXT))+ }NavigationLoadOutcome::NetworkFailure(error_text) => {Err(anyhow::Error::msg(error_text))}@@ -3247,6 +3263,21 @@ impl CdpConnection {));}+ if response_status_has_no_content(head.status) {+ let network_progress = body_progress_source.body_network_progress_for_response_head(+ &request_method,+ &request_headers,+ &head,+ network_observation_journal,+ );+ return Ok(NavigationLoadOutcome::NoContent(Box::new(+ NoContentNavigation {+ final_url: head.final_url,+ network_progress,+ },+ )));+ }+if load_inputs.browser_context_id.is_none() {let page_reservation = self.standalone_navigation_engine@@ -3595,53 +3626,20 @@ async fn prepare_captured_document_response_with_engine_async(synthetic_body: bool,reply_boundary: RendererReplyBoundary,) -> anyhow::Result<ResponseCommitReady> {- let network_extra_info_available = !network_observation_journal.is_empty();- body_progress_source.emit_response_metadata(+ let body_network_progress_state = body_progress_source.body_network_progress_for_response_head(&request_method,- &request_headers.to_byte_strings(),- head.request_cookie_report.as_ref(),- &head.redirect_chain,- &head.final_url,- head.status,- &head.headers,- &head.cookie_set_reports,- &network_observation_journal,- network_extra_info_available,- head.from_cache,- head.negotiated_http_version,+ &request_headers,+ &head,+ network_observation_journal,);let (fetch_subresource_interception_enabled, fetch_subresource_interception_resource_type) =load_inputs.fetch_subresource_interception;let response_from_cache = head.from_cache;- let negotiated_http_version = head.negotiated_http_version;let final_url = head.final_url;let response_status = head.status;let response_headers = head.headers;- let initial_request_cookie_report = head.request_cookie_report;- let response_cookie_reports = head.cookie_set_reports;let redirected = head.redirected;- let redirect_chain = head- .redirect_chain- .into_iter()- .map(Into::into)- .collect::<Vec<_>>();- let body_network_progress_state = body_progress_source- .body_network_progress_for_completed_events(- CompletedMainDocumentNetworkEvents::new(- request_method.clone(),- request_headers.to_byte_strings(),- initial_request_cookie_report,- response_status,- response_headers.clone(),- response_cookie_reports,- redirect_chain.clone(),- network_extra_info_available,- response_from_cache,- )- .with_negotiated_http_version(negotiated_http_version)- .with_network_observation_journal(network_observation_journal),- );-+ let redirect_count = head.redirect_chain.len();let (body_tx, body_rx) = mpsc::channel(EXTERNAL_RAW_BODY_CHANNEL_CAPACITY);let (completion_tx, completion_rx) = oneshot::channel();let raw_body = moli_core::runtime::ExternalRawDocumentBodyStream::new(body_rx, completion_rx);@@ -3658,7 +3656,7 @@ async fn prepare_captured_document_response_with_engine_async(final_url.clone(),load_inputs.navigation_initiator_url.clone(),redirected,- redirect_chain.len(),+ redirect_count,response_status,response_headers.clone(),raw_body,diff --git a/moli-protocol/src/conn/state/mod.rs b/moli-protocol/src/conn/state/mod.rsindex b54a34a86..506939af1 100644--- a/moli-protocol/src/conn/state/mod.rs+++ b/moli-protocol/src/conn/state/mod.rs@@ -135,7 +135,7 @@ pub(crate) use target_state::{pub(crate) use navigation_outcome::{CompletedDownloadBody, CompletedDownloadBodyArtifact};pub use navigation_outcome::{DownloadNavigation, LoadedNavigation, NavigationDispatchState, NavigationLoadOutcome,- NavigationRequestLoadPolicy, TargetInfo,+ NavigationRequestLoadPolicy, NoContentNavigation, TargetInfo,};pub(crate) use navigation_outcome::{NETWORK_ERROR_PAGE_URL, NavigationResultProjection, NavigationSourceDocumentSecurityContext,diff --git a/moli-protocol/src/conn/state/navigation_outcome.rs b/moli-protocol/src/conn/state/navigation_outcome.rsindex dc3ba5074..34c4e88d6 100644--- a/moli-protocol/src/conn/state/navigation_outcome.rs+++ b/moli-protocol/src/conn/state/navigation_outcome.rs@@ -12,6 +12,7 @@ use crate::automation::FrontendProtocol;use crate::conn::{CommandOwnerScope, ResponseCommitReady};use crate::domains::network::{CompletedDocumentProgressTransfer, CompletedDownloadProgressTransfer,+ MainDocumentBodyNetworkProgress,};use super::browser_context::BrowserContext;@@ -222,11 +223,19 @@ pub struct DownloadNavigation {pub(crate) progress_transfer: CompletedDownloadProgressTransfer,}+#[derive(Debug)]+/// A 204/205 response retains the current Document and aborts the navigation.+pub struct NoContentNavigation {+ pub(crate) final_url: Url,+ pub(crate) network_progress: MainDocumentBodyNetworkProgress,+}+#[derive(Debug)]pub enum NavigationLoadOutcome {ResponseCommitReady(Box<ResponseCommitReady>),Loaded(Box<LoadedNavigation>),Download(Box<DownloadNavigation>),+ NoContent(Box<NoContentNavigation>),NetworkFailure(String),}diff --git a/moli-protocol/src/conn/tests/resource_runtime.rs b/moli-protocol/src/conn/tests/resource_runtime.rsindex 81c44b2dd..8308a9933 100644--- a/moli-protocol/src/conn/tests/resource_runtime.rs+++ b/moli-protocol/src/conn/tests/resource_runtime.rs@@ -71,6 +71,9 @@ async fn commit_navigation_outcome_for_session_test(NavigationLoadOutcome::Download(_) => {panic!("test navigation should not resolve to a download")}+ NavigationLoadOutcome::NoContent(_) => {+ panic!("test navigation should produce a document")+ }NavigationLoadOutcome::NetworkFailure(error_text) => {panic!("test navigation should not fail: {error_text}")}diff --git a/moli-protocol/src/domains/network/main_document_progress/gate.rs b/moli-protocol/src/domains/network/main_document_progress/gate.rsindex 68a1dba90..cc3eeb26a 100644--- a/moli-protocol/src/domains/network/main_document_progress/gate.rs+++ b/moli-protocol/src/domains/network/main_document_progress/gate.rs@@ -277,7 +277,7 @@ impl MainDocumentProgressQueueHandle {self.lock_drain().append_source(source);}- fn mark_output_visible_until(&self, boundary: MainDocumentProgressOutputBoundary) {+ pub(super) fn mark_output_visible_until(&self, boundary: MainDocumentProgressOutputBoundary) {self.lock_drain().mark_output_visible_until(boundary);}diff --git a/moli-protocol/src/domains/network/main_document_progress/mod.rs b/moli-protocol/src/domains/network/main_document_progress/mod.rsindex 27087b8cf..639e92785 100644--- a/moli-protocol/src/domains/network/main_document_progress/mod.rs+++ b/moli-protocol/src/domains/network/main_document_progress/mod.rs@@ -11,7 +11,7 @@ use moli_core::page::{};use moli_fetch::{NegotiatedHttpVersion, NetworkExchangeObservation, NetworkObservationJournal, RedirectInfo,- StreamingRawResponse,+ RequestHeaders, ResponseHead, StreamingRawResponse,};use std::sync::Arc;use url::Url;@@ -20,14 +20,16 @@ use crate::automation::DevToolsRequestFailure;use crate::conn::{BackgroundEventSender, BackgroundProtocolEvent, CapturedBody, CdpConnection,CompletedDownloadBodyArtifact, DownloadNavigation, LoadedNavigation, NavigationDispatchState,- NavigationLoadOutcome, NavigationRequestBlocked, ResponseCommitReady, TargetRuntimeSlot,+ NavigationLoadOutcome, NavigationRequestBlocked, NoContentNavigation, ResponseCommitReady,+ TargetRuntimeSlot,};#[cfg(test)]use gate::MainDocumentProgressDrain;pub(crate) use gate::{MainDocumentProgressBackgroundEventBarrier, MainDocumentProgressGate};use gate::{- MainDocumentProgressEmission, MainDocumentProgressEventBatch, MainDocumentProgressOutputTarget,+ MainDocumentProgressEmission, MainDocumentProgressEventBatch,+ MainDocumentProgressOutputBoundary, MainDocumentProgressOutputTarget,MainDocumentProgressPhase, MainDocumentProgressQueueHandle, MainDocumentProgressSource,};@@ -371,6 +373,9 @@ fn materialize_navigation_load_outcome(NavigationLoadOutcome::Download(navigation) => MaterializedNavigationLoadOutcome::Download(materialize_download_navigation_progress(conn, state, *navigation),),+ NavigationLoadOutcome::NoContent(navigation) => {+ materialize_no_content_navigation_progress(conn, state, *navigation)+ }NavigationLoadOutcome::NetworkFailure(error_text) => {MaterializedNavigationLoadOutcome::Failed(materialize_failed_navigation_progress(conn,@@ -426,6 +431,47 @@ pub(crate) fn materialize_navigation_failure_preserving_committed_document())}+fn materialize_no_content_navigation_progress(+ conn: &CdpConnection,+ state: &NavigationDispatchState,+ navigation: NoContentNavigation,+) -> MaterializedNavigationLoadOutcome {+ let error_text = moli_fetch::NET_ERR_ABORTED_ERROR_TEXT;+ let progress_gate = match navigation.network_progress.into_completed_body_events() {+ Some(events) => {+ let context = CompletedMainDocumentProgressContext::for_navigation(+ conn,+ state,+ completed_body_main_document_network_request_id(+ main_document_network_observed(conn, state.session_id.as_deref()),+ state.request_id.clone(),+ ),+ );+ let batches = MainDocumentNavigationProgressEventBatches::new(+ context.request_and_redirect_progress_events(&events),+ context.response_received_progress_events(&events, &navigation.final_url, 0),+ observed_navigation_failure_event(conn, state, error_text)+ .into_iter()+ .collect(),+ );+ let queue = MainDocumentProgressQueueHandle::from_source(+ MainDocumentProgressSource::completed_body(batches),+ );+ // No Document commit will advance visibility for this response.+ queue+ .mark_output_visible_until(MainDocumentProgressOutputBoundary::BodyFinishedVisible);+ MainDocumentProgressGate::from_queue(queue)+ }+ None => failed_navigation_progress_gate(conn, state, error_text),+ };+ MaterializedNavigationLoadOutcome::Failed(MaterializedFailedDocumentProgress {+ error_text: error_text.to_owned(),+ document_policy: FailedNavigationDocumentPolicy::PreserveCommittedDocument,+ response_mode: FailedNavigationResponseMode::CdpErrorTextResult,+ progress_gate,+ })+}+fn materialize_download_navigation_progress(conn: &CdpConnection,state: &NavigationDispatchState,@@ -545,17 +591,10 @@ fn completed_or_streaming_document_progress_queue(MainDocumentProgressSource::streaming(),);};- let context = CompletedMainDocumentProgressContext::new(- main_document_network_event_session_ids(conn, state.session_id.as_deref()),+ let context = CompletedMainDocumentProgressContext::for_navigation(+ conn,+ state,completed_body_main_document_network_request_id(network_enabled, request_id),- state.request_announced,- state.requested_url.clone(),- state.request_method.clone(),- state.request_body.clone(),- state.request_headers.to_byte_strings(),- state.loader_id.clone(),- state.frame_id.clone(),- state.timestamp,);MainDocumentProgressQueueHandle::from_source(MainDocumentProgressSource::completed_body(context.event_batches(&events, final_url, encoded_data_length),@@ -599,6 +638,50 @@ impl MainDocumentBodyProgressSource {}}+ pub(crate) fn body_network_progress_for_response_head(+ &self,+ request_method: &str,+ request_headers: &RequestHeaders,+ head: &ResponseHead,+ network_observation_journal: NetworkObservationJournal,+ ) -> MainDocumentBodyNetworkProgress {+ let network_extra_info_available = !network_observation_journal.is_empty();+ let request_headers = request_headers.to_byte_strings();+ self.emit_response_metadata(+ request_method,+ &request_headers,+ head.request_cookie_report.as_ref(),+ &head.redirect_chain,+ &head.final_url,+ head.status,+ &head.headers,+ &head.cookie_set_reports,+ &network_observation_journal,+ network_extra_info_available,+ head.from_cache,+ head.negotiated_http_version,+ );+ self.body_network_progress_for_completed_events(+ CompletedMainDocumentNetworkEvents::new(+ request_method.to_owned(),+ request_headers,+ head.request_cookie_report.clone(),+ head.status,+ head.headers.clone(),+ head.cookie_set_reports.clone(),+ head.redirect_chain+ .iter()+ .cloned()+ .map(Into::into)+ .collect(),+ network_extra_info_available,+ head.from_cache,+ )+ .with_negotiated_http_version(head.negotiated_http_version)+ .with_network_observation_journal(network_observation_journal),+ )+ }+pub(crate) fn emit_response_metadata(&self,final_request_method: &str,@@ -1589,6 +1672,25 @@ struct CompletedMainDocumentProgressContext {}impl CompletedMainDocumentProgressContext {+ fn for_navigation(+ conn: &CdpConnection,+ state: &NavigationDispatchState,+ request_id: Option<String>,+ ) -> Self {+ Self::new(+ main_document_network_event_session_ids(conn, state.session_id.as_deref()),+ request_id,+ state.request_announced,+ state.requested_url.clone(),+ state.request_method.clone(),+ state.request_body.clone(),+ state.request_headers.to_byte_strings(),+ state.loader_id.clone(),+ state.frame_id.clone(),+ state.timestamp,+ )+ }+fn new(session_ids: Vec<Option<String>>,request_id: Option<String>,diff --git a/moli-protocol/src/domains/page/tests/navigation/navigation_flow.rs b/moli-protocol/src/domains/page/tests/navigation/navigation_flow.rsindex 24ab0c24b..a88ce55f0 100644--- a/moli-protocol/src/domains/page/tests/navigation/navigation_flow.rs+++ b/moli-protocol/src/domains/page/tests/navigation/navigation_flow.rs@@ -1,5 +1,97 @@use super::*;+#[tokio::test]+async fn no_content_navigation_retains_document_and_reports_abort() {+ tokio::task::LocalSet::new()+ .run_until(async {+ for background in [false, true] {+ for status in [204, 205] {+ let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();+ let address = listener.local_addr().unwrap();+ let server = tokio::spawn(async move {+ axum::serve(+ listener,+ axum::Router::new().route(+ "/empty",+ axum::routing::get(move || async move {+ (+ axum::http::StatusCode::from_u16(status).unwrap(),+ [("content-type", "text/plain")],+ "",+ )+ }),+ ),+ )+ .await+ .unwrap();+ });+ let mut ctx = TestContext::new();+ load_bc_with_session(&mut ctx, "BID-1", "TID-1", "SID-1", "about:blank");+ ensure_initial_document_for_session(&mut ctx, Some("SID-1")).await;+ for (id, method, params) in [+ (1, "Page.enable", json!({})),+ (2, "Network.enable", json!({})),+ (3, "Runtime.enable", json!({})),+ (4, "Page.setLifecycleEventsEnabled", json!({"enabled":true})),+ (5, "Runtime.evaluate", json!({"expression":+ "globalThis.retainedMarker=42;document.body.innerHTML='<input id=field value=retained>'"})),+ (6, "Page.getNavigationHistory", json!({})),+ ] {+ ctx.process_async(json!({"id":id,"method":method,"params":params,"sessionId":"SID-1"})).await;+ assert!(ctx.sent.iter().find(|message| message["id"] == id).unwrap()["error"].is_null());+ }+ let history = take_response_by_id(&mut ctx, 6)["result"].clone();+ ctx.sent.clear();+ if background {+ ctx.enable_background_navigation_scheduler_for_test();+ }+ let url = format!("http://{address}/empty");+ ctx.process_and_wait_for_response_async(json!({+ "id":7,"method":"Page.navigate","sessionId":"SID-1","params":{"url":url}+ })).await;+ let reply = take_response_by_id(&mut ctx, 7);+ assert!(reply["error"].is_null(), "{reply}");+ assert_eq!(reply["result"]["errorText"], "net::ERR_ABORTED");+ assert_eq!(reply["result"]["isDownload"], false);+ let loader_id = &reply["result"]["loaderId"];+ assert!(loader_id.is_string());+ wait_until_scheduler_message(&mut ctx, "no-content terminal", |message| {+ message["method"] == "Network.loadingFailed"+ && message["params"]["requestId"] == *loader_id+ }).await;+ let response = ctx.sent.iter().find(|message| {+ message["method"] == "Network.responseReceived"+ && message["params"]["requestId"] == *loader_id+ }).unwrap();+ assert_eq!(response["params"]["response"]["status"], status);+ assert_eq!(response["params"]["response"]["url"], url);+ let terminals: Vec<_> = ctx.sent.iter().filter(|message| {+ matches!(message["method"].as_str(), Some("Network.loadingFailed" | "Network.loadingFinished"))+ && message["params"]["requestId"] == *loader_id+ }).collect();+ assert_eq!(terminals.len(), 1);+ assert_eq!(terminals[0]["params"]["errorText"], "net::ERR_ABORTED");+ assert_eq!(terminals[0]["params"]["canceled"], true);+ assert!(!ctx.sent.iter().any(|message| {+ matches!(message["method"].as_str(), Some("Page.frameNavigated" | "Runtime.executionContextsCleared"))+ || message["method"] == "Page.lifecycleEvent"+ && message["params"]["loaderId"] == *loader_id+ && message["params"]["name"] == "DOMContentLoaded"+ }));+ ctx.process_async(json!({"id":8,"method":"Runtime.evaluate","sessionId":"SID-1",+ "params":{"expression":"[location.href,retainedMarker,document.querySelector('#field').value]","returnByValue":true}})).await;+ assert_eq!(take_response_by_id(&mut ctx, 8)["result"]["result"]["value"], json!(["about:blank",42,"retained"]));+ ctx.process_async(json!({"id":9,"method":"Page.getNavigationHistory","sessionId":"SID-1"})).await;+ assert_eq!(take_response_by_id(&mut ctx, 9)["result"], history);+ ctx.process_and_wait_for_response_async(json!({"id":10,"method":"Page.navigate","sessionId":"SID-1",+ "params":{"url":"data:text/html,<body>next document"}})).await;+ assert!(take_response_by_id(&mut ctx, 10)["result"]["errorText"].is_null());+ server.abort();+ }+ }+ }).await;+}+#[tokio::test(flavor = "multi_thread")]async fn data_url_commit_applies_preloads_worlds_and_bindings_before_author_script() {let mut ctx = TestContext::new();