@@ -7,8 +7,10 @@ use anyhow::Result;
77use clap:: { Parser , Subcommand } ;
88
99use crate :: browser:: daemon:: client:: DaemonClient ;
10- use crate :: browser:: daemon:: protocol:: DaemonCommand ;
11- use crate :: util:: output;
10+ use crate :: browser:: daemon:: process;
11+ use crate :: browser:: daemon:: protocol:: { DaemonCommand , DaemonCreateParams } ;
12+ use crate :: status;
13+ use crate :: util:: { api, output} ;
1214
1315// ── Shared arg types ────────────────────────────────────────────────
1416
@@ -1169,17 +1171,34 @@ async fn dispatch_action(client: &mut DaemonClient, action: ActionCommand) -> Re
11691171async fn ensure_daemon ( session_name : Option < & str > ) -> Result < DaemonClient > {
11701172 let name = session_name. unwrap_or ( "default" ) ;
11711173 // connect() already cleans up stale sockets via cleanup_if_dead()
1172- DaemonClient :: connect ( name) . await . map_err ( |_| {
1173- if name == "default" {
1174- anyhow:: anyhow!(
1175- "No active browser session. Start one with: steel browser start"
1176- )
1177- } else {
1178- anyhow:: anyhow!(
1179- "No running session \" {name}\" . Start one with: steel browser start --session {name}"
1180- )
1181- }
1182- } )
1174+ if let Ok ( client) = DaemonClient :: connect ( name) . await {
1175+ return Ok ( client) ;
1176+ }
1177+
1178+ status ! ( "Starting browser session..." ) ;
1179+
1180+ let ( mode, base_url, auth) = api:: resolve_with_auth ( ) ;
1181+ let params = DaemonCreateParams {
1182+ api_key : auth. api_key ,
1183+ base_url,
1184+ mode,
1185+ session_name : name. to_string ( ) ,
1186+ stealth : false ,
1187+ proxy_url : None ,
1188+ timeout_ms : None ,
1189+ headless : None ,
1190+ region : None ,
1191+ solve_captcha : false ,
1192+ profile_id : None ,
1193+ persist_profile : false ,
1194+ namespace : None ,
1195+ credentials : false ,
1196+ } ;
1197+
1198+ let child = process:: spawn_daemon ( name, & params) ?;
1199+ process:: wait_for_daemon ( name, child, std:: time:: Duration :: from_secs ( 30 ) ) . await ?;
1200+
1201+ DaemonClient :: connect ( name) . await
11831202}
11841203
11851204/// On action failure, check if daemon is still reachable. If not, suggest restarting.
0 commit comments