Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cli/src/native/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,9 @@ async fn auto_launch(state: &mut DaemonState) -> Result<(), String> {
}
let engine = env::var("AGENT_BROWSER_ENGINE").ok();

// Extract storage_state before options is moved into BrowserManager::launch.
let storage_state_path = options.storage_state.clone();

// Store proxy credentials for Fetch.authRequired handling
let has_proxy_auth = options.proxy_username.is_some();
if has_proxy_auth {
Expand All @@ -1527,6 +1530,7 @@ async fn auto_launch(state: &mut DaemonState) -> Result<(), String> {
state.start_dialog_handler();
state.update_stream_client().await;
try_auto_restore_state(state).await;
try_load_storage_state(state, &storage_state_path).await;
return Ok(());
}

Expand All @@ -1538,6 +1542,7 @@ async fn auto_launch(state: &mut DaemonState) -> Result<(), String> {
state.start_dialog_handler();
state.update_stream_client().await;
try_auto_restore_state(state).await;
try_load_storage_state(state, &storage_state_path).await;
return Ok(());
}

Expand Down Expand Up @@ -1572,6 +1577,7 @@ async fn auto_launch(state: &mut DaemonState) -> Result<(), String> {
state.update_stream_client().await;
write_provider_file(&state.session_id, &p);
try_auto_restore_state(state).await;
try_load_storage_state(state, &storage_state_path).await;
return Ok(());
}
Err(e) => {
Expand Down Expand Up @@ -1604,6 +1610,7 @@ async fn auto_launch(state: &mut DaemonState) -> Result<(), String> {
}

try_auto_restore_state(state).await;
try_load_storage_state(state, &storage_state_path).await;
Ok(())
}

Expand Down Expand Up @@ -1665,6 +1672,17 @@ async fn try_auto_restore_state(state: &mut DaemonState) {
}
}

/// Load storage state from AGENT_BROWSER_STATE if set.
async fn try_load_storage_state(state: &DaemonState, path: &Option<String>) {
if let Some(ref path) = path {
if let Some(ref mgr) = state.browser {
if let Ok(session_id) = mgr.active_session_id() {
let _ = state::load_state(&mgr.client, session_id, path).await;
}
}
}
}

// ---------------------------------------------------------------------------
// Phase 1 handlers
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -1922,6 +1940,15 @@ async fn handle_launch(cmd: &Value, state: &mut DaemonState) -> Result<Value, St
state.start_dialog_handler();
state.update_stream_client().await;

// Load storage state (--state / storageState) if provided.
if let Some(state_path) = storage_state {
if let Some(ref mgr) = state.browser {
if let Ok(session_id) = mgr.active_session_id() {
let _ = state::load_state(&mgr.client, session_id, state_path).await;
}
}
}

// Enable Fetch interception (domain filtering and/or proxy auth).
// Only call Fetch.enable once to avoid overwriting handleAuthRequests.
{
Expand Down
Loading
Loading