Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
refactor(cdp): preserve typed navigation network errors
ldm05be3c7b64441
diff --git a/moli-protocol/src/conn.rs b/moli-protocol/src/conn.rsindex a92d770bc..995ab9c34 100644--- a/moli-protocol/src/conn.rs+++ b/moli-protocol/src/conn.rs@@ -48,6 +48,7 @@ mod dispatch;mod downloads;mod fetch_support;mod inspector_route;+mod navigation_error;mod output;mod page_state;mod popup_activation_work;@@ -498,6 +499,7 @@ impl CommandDispatchContext {}pub(crate) use moli_protocol_cdp::{DEFAULT_LOADER_ID, monotonic_timestamp_seconds};+pub use navigation_error::NavigationNetworkError;pub(crate) use output::NavigationBackgroundEvent;pub use output::{BackgroundCommandResponsePayload, BackgroundEventSender, BackgroundProtocolEvent,diff --git a/moli-protocol/src/conn/navigation_error.rs b/moli-protocol/src/conn/navigation_error.rsnew file mode 100644index 000000000..4ce96c751--- /dev/null+++ b/moli-protocol/src/conn/navigation_error.rs@@ -0,0 +1,24 @@+use std::{error::Error, fmt};++use url::Url;++/// A failed navigation request, captured where the network policy is enforced.+///+/// This is an error cause rather than display context, so callers can recover+/// its request identity through `anyhow::Error::downcast_ref` after adding+/// diagnostic context along the navigation pipeline.+#[derive(Debug)]+pub struct NavigationNetworkError {+ pub error_text: String,+ pub unreachable_url: Url,+ pub request_method: String,+ pub request_headers: Vec<(String, String)>,+}++impl fmt::Display for NavigationNetworkError {+ fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {+ formatter.write_str(&self.error_text)+ }+}++impl Error for NavigationNetworkError {}diff --git a/moli-protocol/src/conn/runtime_load.rs b/moli-protocol/src/conn/runtime_load.rsindex 16189d76a..e2a98f55a 100644--- a/moli-protocol/src/conn/runtime_load.rs+++ b/moli-protocol/src/conn/runtime_load.rs@@ -1,3 +1,4 @@+use anyhow::Context;use data_url::DataUrl;use moli_core::{RendererOutputFence,@@ -2206,7 +2207,8 @@ impl CdpConnection {request_headers,MainDocumentBodyProgressSource::default(),)- .await?;+ .await+ .map_err(|error| format!("{error:#}"))?;self.commit_navigation_load_outcome_for_owner_async(owner, navigation).await}@@ -2243,7 +2245,7 @@ impl CdpConnection {raw_url: &str,body: Option<String>,request_headers: Vec<(String, String)>,- ) -> Result<NavigationLoadOutcome, String> {+ ) -> anyhow::Result<NavigationLoadOutcome> {self.load_navigation_request_via_runtime_with_network_events_async(None,method,@@ -2265,7 +2267,7 @@ impl CdpConnection {request_headers: Vec<(String, String)>,body_progress_source: MainDocumentBodyProgressSource,request_load_policy: NavigationRequestLoadPolicy,- ) -> Result<NavigationLoadOutcome, String> {+ ) -> anyhow::Result<NavigationLoadOutcome> {let owner = CommandOwnerScope::capture(self, session_id);let load_inputs = apply_navigation_request_load_policy(self.navigation_load_inputs_for_owner(&owner),@@ -2287,7 +2289,7 @@ impl CdpConnection {&mut self,navigation: &NavigationDispatchState,body_progress_source: MainDocumentBodyProgressSource,- ) -> Result<NavigationLoadOutcome, String> {+ ) -> anyhow::Result<NavigationLoadOutcome> {self.load_navigation_request_via_runtime_with_network_events_and_load_inputs_async(&navigation.owner,self.navigation_load_inputs_for_navigation(navigation),@@ -2298,20 +2300,17 @@ impl CdpConnection {body_progress_source,).await+ .context("failed to load document")}pub(crate) async fn prepare_navigation_load_error_for_navigation_async(&mut self,navigation: &NavigationDispatchState,- error_text: String,- ) -> Result<NavigationLoadOutcome, String> {- // Fetch continuation loaders currently share a String error boundary- // for protocol errors and network failures. Offline emulation is a- // navigation failure that commits an error Document, just as it does- // in BackgroundNavigationLoadJob; retain other errors unchanged.- if error_text != NET_ERR_INTERNET_DISCONNECTED_ERROR_TEXT {- return Err(error_text);- }+ error: anyhow::Error,+ ) -> anyhow::Result<NavigationLoadOutcome> {+ let Some(network_error) = error.downcast_ref::<NavigationNetworkError>() else {+ return Err(error);+ };let load_inputs = self.navigation_load_inputs_for_navigation(navigation);let mut engine = self.navigation_engine_handle_for_load_inputs(&load_inputs);@@ -2321,13 +2320,15 @@ impl CdpConnection {&mut engine,page_reservation,&load_inputs,- navigation.requested_url.clone(),- navigation.request_method.clone(),- navigation.request_headers.clone(),- error_text,+ network_error.unreachable_url.clone(),+ network_error.request_method.clone(),+ network_error.request_headers.clone(),+ network_error.error_text.clone(),RendererReplyBoundary::Stage,).await+ .map_err(anyhow::Error::msg)+ .context("failed to prepare network error document")}#[allow(clippy::too_many_arguments)]@@ -2340,7 +2341,7 @@ impl CdpConnection {body: Option<Vec<u8>>,request_headers: Vec<(String, String)>,body_progress_source: MainDocumentBodyProgressSource,- ) -> Result<NavigationLoadOutcome, String> {+ ) -> anyhow::Result<NavigationLoadOutcome> {if load_inputs.browser_context_id.is_none() {let page_reservation = self.standalone_navigation_engine@@ -2356,7 +2357,7 @@ impl CdpConnection {).await{- return navigation;+ return navigation.map_err(anyhow::Error::msg);}if let Some(navigation) = load_data_url_navigation_with_engine_async(self.standalone_navigation_engine.ensure_mut(),@@ -2369,7 +2370,7 @@ impl CdpConnection {).await{- return navigation;+ return navigation.map_err(anyhow::Error::msg);}} else {let mut inline_engine = self.navigation_engine_handle_for_load_inputs(&load_inputs);@@ -2387,7 +2388,7 @@ impl CdpConnection {).await{- return navigation;+ return navigation.map_err(anyhow::Error::msg);}if let Some(navigation) = load_data_url_navigation_with_engine_async(&mut inline_engine,@@ -2400,17 +2401,13 @@ impl CdpConnection {).await{- return navigation;+ return navigation.map_err(anyhow::Error::msg);}}- ensure_url_not_blocked_for_load_inputs(&load_inputs, raw_url)?;- if load_inputs.network_offline {- return Err(NET_ERR_INTERNET_DISCONNECTED_ERROR_TEXT.to_owned());- }-+ validate_navigation_network_request(&load_inputs, method, raw_url, &request_headers)?;let requested_url = Url::parse(raw_url)- .map_err(|error| format!("failed to parse request url `{raw_url}`: {error}"))?;+ .with_context(|| format!("failed to parse request url `{raw_url}`"))?;let response = self.fetch_navigation_streaming_raw_response_with_load_inputs_async(&load_inputs,@@ -2433,6 +2430,7 @@ impl CdpConnection {body_progress_source,).await+ .map_err(anyhow::Error::msg)}pub(crate) fn navigation_load_job_for_navigation(@@ -3016,16 +3014,13 @@ impl CdpConnection {body: Option<String>,request_headers: Vec<(String, String)>,auth: Option<SubresourceAuthCredentials>,- ) -> Result<NetworkFetchResult<NavigationResponse>, String> {+ ) -> anyhow::Result<NetworkFetchResult<NavigationResponse>> {let load_inputs = self.navigation_load_inputs_for_session_owner(None);- ensure_url_not_blocked_for_load_inputs(&load_inputs, raw_url)?;- if load_inputs.network_offline {- return Err(NET_ERR_INTERNET_DISCONNECTED_ERROR_TEXT.to_owned());- }+ validate_navigation_network_request(&load_inputs, method, raw_url, &request_headers)?;let resource_storage = load_inputs.resource_storage_handles();let engine = self.navigation_engine_for_load_inputs_mut(&load_inputs)- .ok_or_else(|| "navigation Page engine unavailable".to_owned())?;+ .context("navigation Page engine unavailable")?;engine.set_bypass_service_worker(load_inputs.bypass_service_worker);engine.set_cache_disabled(load_inputs.cache_disabled);engine@@ -3041,7 +3036,7 @@ impl CdpConnection {auth,).await- .map_err(|error| format!("failed to fetch page `{raw_url}`: {error}"))+ .with_context(|| format!("failed to fetch page `{raw_url}`"))}pub(crate) async fn fetch_navigation_auth_raw_response_for_owner_async(@@ -3053,15 +3048,12 @@ impl CdpConnection {body: Option<Vec<u8>>,request_headers: Vec<(String, String)>,auth: SubresourceAuthCredentials,- ) -> Result<NetworkFetchResult<RawResponse>, String> {+ ) -> anyhow::Result<NetworkFetchResult<RawResponse>> {let load_inputs = apply_navigation_request_load_policy(self.navigation_load_inputs_for_owner(owner),request_load_policy,);- ensure_url_not_blocked_for_load_inputs(&load_inputs, raw_url)?;- if load_inputs.network_offline {- return Err(NET_ERR_INTERNET_DISCONNECTED_ERROR_TEXT.to_owned());- }+ validate_navigation_network_request(&load_inputs, method, raw_url, &request_headers)?;let mut request = Request::new_browser_bytes(method,@@ -3073,7 +3065,7 @@ impl CdpConnection {.as_ref().map_or(moli_url::WebOrigin::Opaque, moli_url::WebOrigin::from_url),)- .map_err(|error| format!("failed to build request for `{raw_url}`: {error}"))?+ .with_context(|| format!("failed to build request for `{raw_url}`"))?.with_top_level_navigation_cookie_context().with_page_network_policy().with_browser_navigation_kind(load_inputs.browser_navigation_kind);@@ -3088,12 +3080,13 @@ impl CdpConnection {request.set_auth(Some(auth.into()));let loader = self- .ensure_resource_request_client_for_navigation_load_inputs(&load_inputs)?+ .ensure_resource_request_client_for_navigation_load_inputs(&load_inputs)+ .map_err(anyhow::Error::msg)?.clone();loader.fetch_raw_with_network_metadata(request).await- .map_err(|error| format!("failed to fetch page `{raw_url}`: {error}"))+ .with_context(|| format!("failed to fetch page `{raw_url}`"))}pub async fn fetch_navigation_streaming_raw_response_async(@@ -3103,7 +3096,7 @@ impl CdpConnection {body: Option<String>,request_headers: Vec<(String, String)>,auth: Option<SubresourceAuthCredentials>,- ) -> Result<NetworkFetchResult<StreamingRawResponse>, String> {+ ) -> anyhow::Result<NetworkFetchResult<StreamingRawResponse>> {let load_inputs = self.navigation_load_inputs_for_session_owner(None);self.fetch_navigation_streaming_raw_response_with_load_inputs_async(&load_inputs,@@ -3125,7 +3118,7 @@ impl CdpConnection {body: Option<Vec<u8>>,request_headers: Vec<(String, String)>,auth: Option<SubresourceAuthCredentials>,- ) -> Result<NetworkFetchResult<StreamingRawResponse>, String> {+ ) -> anyhow::Result<NetworkFetchResult<StreamingRawResponse>> {let load_inputs = apply_navigation_request_load_policy(self.navigation_load_inputs_for_owner(owner),request_load_policy,@@ -3149,11 +3142,8 @@ impl CdpConnection {body: Option<Vec<u8>>,request_headers: Vec<(String, String)>,auth: Option<SubresourceAuthCredentials>,- ) -> Result<NetworkFetchResult<StreamingRawResponse>, String> {- ensure_url_not_blocked_for_load_inputs(load_inputs, raw_url)?;- if load_inputs.network_offline {- return Err(NET_ERR_INTERNET_DISCONNECTED_ERROR_TEXT.to_owned());- }+ ) -> anyhow::Result<NetworkFetchResult<StreamingRawResponse>> {+ validate_navigation_network_request(load_inputs, method, raw_url, &request_headers)?;let mut request = Request::new_browser_bytes(method,@@ -3165,7 +3155,7 @@ impl CdpConnection {.as_ref().map_or(moli_url::WebOrigin::Opaque, moli_url::WebOrigin::from_url),)- .map_err(|error| format!("failed to build request for `{raw_url}`: {error}"))?+ .with_context(|| format!("failed to build request for `{raw_url}`"))?.with_top_level_navigation_cookie_context().with_page_network_policy().with_browser_navigation_kind(load_inputs.browser_navigation_kind);@@ -3180,12 +3170,13 @@ impl CdpConnection {request.set_auth(auth.map(Into::into));let loader = self- .ensure_resource_request_client_for_navigation_load_inputs(load_inputs)?+ .ensure_resource_request_client_for_navigation_load_inputs(load_inputs)+ .map_err(anyhow::Error::msg)?.clone();loader.fetch_raw_stream_with_cancel_and_network_metadata(request, FetchCancelHandle::new()).await- .map_err(|error| format!("failed to fetch page `{raw_url}`: {error}"))+ .with_context(|| format!("failed to fetch page `{raw_url}`"))}pub async fn build_navigation_from_network_response_async(@@ -3670,13 +3661,13 @@ impl CdpConnection {pub(crate) async fn collect_navigation_streaming_raw_response_async(&mut self,response: NetworkFetchResult<StreamingRawResponse>,- ) -> Result<NetworkFetchResult<RawResponse>, String> {+ ) -> anyhow::Result<NetworkFetchResult<RawResponse>> {let (response, network_observation_journal) =response.into_parts_with_observation_journal();let response = response.into_materialized_raw_response().await- .map_err(|error| format!("failed to read page body from stream: {error}"))?;+ .context("failed to read page body from stream")?;Ok(NetworkFetchResult::with_observation_journal(response,network_observation_journal,@@ -3936,6 +3927,27 @@ async fn prepare_captured_document_response_with_engine_async(})}+fn validate_navigation_network_request(+ load_inputs: &TargetNavigationLoadInputs,+ method: &str,+ raw_url: &str,+ request_headers: &[(String, String)],+) -> anyhow::Result<()> {+ ensure_url_not_blocked_for_load_inputs(load_inputs, raw_url).map_err(anyhow::Error::msg)?;+ if load_inputs.network_offline {+ let requested_url = Url::parse(raw_url)+ .with_context(|| format!("failed to parse request url `{raw_url}`"))?;+ return Err(NavigationNetworkError {+ error_text: NET_ERR_INTERNET_DISCONNECTED_ERROR_TEXT.to_owned(),+ unreachable_url: requested_url,+ request_method: method.to_owned(),+ request_headers: request_headers.to_vec(),+ }+ .into());+ }+ Ok(())+}+fn ensure_url_not_blocked_for_load_inputs(load_inputs: &TargetNavigationLoadInputs,raw_url: &str,diff --git a/moli-protocol/src/conn/tests/mod.rs b/moli-protocol/src/conn/tests/mod.rsindex 28bf217a1..9c9a7cba8 100644--- a/moli-protocol/src/conn/tests/mod.rs+++ b/moli-protocol/src/conn/tests/mod.rs@@ -44,6 +44,7 @@ use url::Url;mod cookie_surfaces;mod message;+mod navigation_error;mod resource_runtime;mod site_data;diff --git a/moli-protocol/src/conn/tests/navigation_error.rs b/moli-protocol/src/conn/tests/navigation_error.rsnew file mode 100644index 000000000..c3a29dc4e--- /dev/null+++ b/moli-protocol/src/conn/tests/navigation_error.rs@@ -0,0 +1,169 @@+use super::*;+use crate::conn::{+ CommandOwnerScope, NavigationLoadOutcome, NavigationNetworkError, NavigationRequestLoadPolicy,+};+use moli_core::page::{SubresourceAuthCredentials, SubresourceAuthScheme, SubresourceAuthTarget};++const OFFLINE_ERROR_TEXT: &str = "net::ERR_INTERNET_DISCONNECTED";++fn navigation_fixture() -> (TestContext, NavigationDispatchState) {+ let mut ctx = TestContext::new();+ let mut browser_context = BrowserContext::new("BID-1".to_owned());+ browser_context.set_active_target_id("TID-1");+ browser_context.attach_active_session("SID-1");+ browser_context+ .start_document_navigation_for_active_target("LID-test".to_owned())+ .expect("fixture navigation should start");+ ctx.conn+ .install_browser_context_fixture_for_test(browser_context);+ let navigation = NavigationDispatchState {+ navigate_id: Some(1),+ owner: CommandOwnerScope::for_session("SID-1"),+ result_projection: NavigationResultProjection::Cdp(json!({+ "frameId": "TID-1", "loaderId": "LID-test",+ })),+ frame_id: "TID-1".to_owned(),+ session_id: Some("SID-1".to_owned()),+ request_id: Some("LID-test".to_owned()),+ loader_id: "LID-test".to_owned(),+ request_announced: true,+ requested_url: Url::parse("https://original.example/document").unwrap(),+ request_method: "GET".to_owned(),+ request_body: None,+ request_body_bytes: None,+ request_headers: Vec::new(),+ request_load_policy: NavigationRequestLoadPolicy::BrowserInitiated,+ timestamp: 0.0,+ source_document_security: Default::default(),+ };+ (ctx, navigation)+}++#[tokio::test(flavor = "multi_thread")]+async fn offline_navigation_loaders_preserve_typed_error_causes_through_context() {+ let (mut ctx, mut navigation) = navigation_fixture();+ navigation.request_method = "POST".to_owned();+ navigation.request_headers = vec![("x-request".to_owned(), "offline".to_owned())];+ ctx.process_async(json!({+ "id": 2,+ "method": "Network.emulateNetworkConditions",+ "sessionId": "SID-1",+ "params": {+ "offline": true, "latency": 0,+ "downloadThroughput": -1, "uploadThroughput": -1,+ },+ }))+ .await;+ ctx.expect_result(2, json!({}), Some("SID-1"));++ let url = navigation.requested_url.as_str();+ let method = &navigation.request_method;+ let headers = &navigation.request_headers;+ let errors = [+ ctx.conn+ .load_navigation_request_via_runtime_with_network_events_for_navigation_async(+ &navigation,+ Default::default(),+ )+ .await+ .expect_err("offline document load must fail"),+ ctx.conn+ .fetch_navigation_response_async(method, url, None, headers.clone(), None)+ .await+ .expect_err("offline response fetch must fail"),+ ctx.conn+ .fetch_navigation_streaming_raw_response_async(method, url, None, headers.clone(), None)+ .await+ .expect_err("offline streaming response fetch must fail"),+ ctx.conn+ .fetch_navigation_auth_raw_response_for_owner_async(+ &navigation.owner,+ navigation.request_load_policy,+ method,+ url,+ None,+ headers.clone(),+ SubresourceAuthCredentials {+ target: SubresourceAuthTarget::Server,+ scheme: SubresourceAuthScheme::Basic,+ username: "test-user".to_owned(),+ password: "test-password".to_owned(),+ },+ )+ .await+ .expect_err("offline authenticated response fetch must fail"),+ ];+ for error in errors {+ let error = error+ .context("failed to load document")+ .context("failed to continue intercepted navigation");+ let network_error = error+ .downcast_ref::<NavigationNetworkError>()+ .expect("navigation request identity must survive diagnostic context");+ assert_eq!(network_error.error_text, OFFLINE_ERROR_TEXT);+ assert_eq!(network_error.unreachable_url, navigation.requested_url);+ assert_eq!(network_error.request_method, *method);+ assert_eq!(network_error.request_headers, *headers);+ assert!(+ error.root_cause().is::<NavigationNetworkError>(),+ "network failure must be the error cause, not a context wrapper: {error:#}"+ );+ }+}++#[tokio::test(flavor = "multi_thread")]+async fn navigation_error_document_uses_typed_failure_request_after_context() {+ let (mut ctx, navigation) = navigation_fixture();+ let unreachable_url = Url::parse("https://redirect.example/unreachable").unwrap();+ let request_headers = vec![("x-request".to_owned(), "failed-hop".to_owned())];+ let error = anyhow::Error::new(NavigationNetworkError {+ error_text: OFFLINE_ERROR_TEXT.to_owned(),+ unreachable_url: unreachable_url.clone(),+ request_method: "POST".to_owned(),+ request_headers: request_headers.clone(),+ })+ .context("failed to load document")+ .context("failed to continue intercepted navigation");+ let outcome = ctx+ .conn+ .prepare_navigation_load_error_for_navigation_async(&navigation, error)+ .await+ .expect("typed network failure should prepare an error document");+ let NavigationLoadOutcome::ResponseCommitReady(prepared) = outcome else {+ panic!("network failure must prepare an error document commit");+ };+ let permit = prepared.issue_commit_permit();+ let loaded = prepared+ .commit(permit)+ .await+ .expect("error document should commit");+ assert_eq!(loaded.requested_url, unreachable_url);+ assert_eq!(loaded.request_method, "POST");+ assert_eq!(loaded.request_headers, request_headers);+ let error_page = loaded+ .network_error_page+ .expect("network error page metadata");+ assert_eq!(error_page.unreachable_url(), &unreachable_url);+ assert_eq!(error_page.error_text(), OFFLINE_ERROR_TEXT);+}++#[tokio::test(flavor = "multi_thread")]+async fn navigation_error_boundary_does_not_classify_display_text_as_network_failure() {+ let (mut ctx, navigation) = navigation_fixture();+ for error in [+ anyhow::anyhow!(OFFLINE_ERROR_TEXT),+ anyhow::anyhow!(OFFLINE_ERROR_TEXT)+ .context("failed to load document")+ .context("failed to continue intercepted navigation"),+ ] {+ let expected_chain = format!("{error:#}");+ let error = ctx+ .conn+ .prepare_navigation_load_error_for_navigation_async(&navigation, error)+ .await+ .expect_err("a matching display string must remain a non-network error");+ assert!(error.downcast_ref::<NavigationNetworkError>().is_none());+ assert_eq!(format!("{error:#}"), expected_chain);+ assert_eq!(error.root_cause().to_string(), OFFLINE_ERROR_TEXT);+ }+}diff --git a/moli-protocol/src/domains/fetch/navigation.rs b/moli-protocol/src/domains/fetch/navigation.rsindex 92be15a5a..3585af28b 100644--- a/moli-protocol/src/domains/fetch/navigation.rs+++ b/moli-protocol/src/domains/fetch/navigation.rs@@ -120,7 +120,7 @@ pub(crate) async fn load_or_pause_navigation_for_auth_into_buffer_async(conn,out,pending,- Err(format!(+ Err(anyhow::anyhow!("Fetch response-stage interception after {auth_scheme} authentication is not supported for navigation without buffering")),)@@ -195,7 +195,8 @@ pub(crate) async fn load_or_pause_navigation_for_auth_into_buffer_async(&pending.navigation,response,)- .await;+ .await+ .map_err(anyhow::Error::msg);complete_or_pause_response_stage_into_buffer_async(conn, out, pending, navigation,)@@ -357,7 +358,8 @@ pub(super) async fn cancel_navigation_auth_as_background_events_async(&pending.navigation,response,)- .await;+ .await+ .map_err(anyhow::Error::msg);complete_or_pause_response_stage_into_buffer_async(conn, &mut output, pending, navigation).await;}@@ -433,23 +435,32 @@ async fn complete_pending_fetch_navigation_result_into_buffer_async(conn: &mut CdpConnection,out: &mut CommandOutputBuffer,pending: PendingFetchNavigation,- navigation: Result<NavigationLoadOutcome, String>,+ navigation: anyhow::Result<NavigationLoadOutcome>,) {let token = pending.document_navigation_token;let navigation_state = pending.navigation;- let navigation =- match navigation {- Err(error_text) => {- Box::pin(conn.prepare_navigation_load_error_for_navigation_async(- &navigation_state,- error_text,- ))- .await- }- navigation => navigation,- };- let navigation =- network::materialize_navigation_load_result(conn, &navigation_state, navigation);+ let navigation = match navigation {+ Err(error) => {+ Box::pin(conn.prepare_navigation_load_error_for_navigation_async(+ &navigation_state,+ error.context("failed to continue intercepted navigation"),+ ))+ .await+ }+ navigation => navigation,+ };+ let navigation = network::materialize_navigation_load_result(+ conn,+ &navigation_state,+ navigation.map_err(|error| {+ tracing::debug!(+ error = ?error,+ session_id = navigation_state.owner.session_id(),+ "intercepted navigation failed"+ );+ error.root_cause().to_string()+ }),+ );complete_tokened_materialized_navigation_into_buffer_async(conn,out,@@ -517,7 +528,8 @@ async fn handle_streaming_response_head_for_navigation_into_buffer_async(response,network::MainDocumentBodyProgressSource::default(),)- .await;+ .await+ .map_err(anyhow::Error::msg);complete_pending_fetch_navigation_result_into_buffer_async(conn, out, pending, navigation).await;return;@@ -530,7 +542,8 @@ async fn handle_streaming_response_head_for_navigation_into_buffer_async(response,network::MainDocumentBodyProgressSource::default(),)- .await;+ .await+ .map_err(anyhow::Error::msg);complete_pending_fetch_navigation_result_into_buffer_async(conn, out, pending, navigation).await;return;@@ -576,7 +589,7 @@ async fn handle_streaming_response_head_for_navigation_into_buffer_async(conn,out,pending,- Err(error),+ Err(anyhow::Error::msg(error)),).await;return;@@ -613,7 +626,7 @@ async fn complete_or_pause_response_stage_into_buffer_async(conn: &mut CdpConnection,out: &mut CommandOutputBuffer,pending: PendingFetchNavigation,- navigation: Result<NavigationLoadOutcome, String>,+ navigation: anyhow::Result<NavigationLoadOutcome>,) {match navigation {Ok(NavigationLoadOutcome::Loaded(_)) if pending.intercept_response => {@@ -625,10 +638,9 @@ async fn complete_or_pause_response_stage_into_buffer_async(conn,out,pending,- Err(+ Err(anyhow::anyhow!("response-stage document pause reached unexpected loaded-navigation path"- .to_owned(),- ),+ )),).await;}@@ -719,7 +731,7 @@ fn pause_buffered_raw_response_stage_navigation_into_buffer(async fn collect_navigation_streaming_response(conn: &mut CdpConnection,response: NetworkFetchResult<StreamingRawResponse>,-) -> Result<NetworkFetchResult<RawResponse>, String> {+) -> anyhow::Result<NetworkFetchResult<RawResponse>> {conn.collect_navigation_streaming_raw_response_async(response).await}