Fix: CLI: state load / profile persistence not usable in v0.7.6 (#268)
* Fix: CLI: state load / profile persistence not usable in v0.7.6 This PR addresses issue #259 * Fix issues identified in code review
This commit is contained in:
+39
-9
@@ -106,7 +106,11 @@ fn run_session(args: &[String], session: &str, json_mode: bool) {
|
||||
} else {
|
||||
println!("Active sessions:");
|
||||
for s in &sessions {
|
||||
let marker = if s == session { color::cyan("→") } else { " ".to_string() };
|
||||
let marker = if s == session {
|
||||
color::cyan("→")
|
||||
} else {
|
||||
" ".to_string()
|
||||
};
|
||||
println!("{} {}", marker, s);
|
||||
}
|
||||
}
|
||||
@@ -201,6 +205,8 @@ fn main() {
|
||||
flags.proxy.as_deref(),
|
||||
flags.proxy_bypass.as_deref(),
|
||||
flags.ignore_https_errors,
|
||||
flags.profile.as_deref(),
|
||||
flags.state.as_deref(),
|
||||
) {
|
||||
Ok(result) => result,
|
||||
Err(e) => {
|
||||
@@ -218,8 +224,13 @@ fn main() {
|
||||
let has_extensions = !flags.extensions.is_empty();
|
||||
let ignored_flags: Vec<&str> = [
|
||||
flags.executable_path.as_ref().map(|_| "--executable-path"),
|
||||
if has_extensions { Some("--extension") } else { None },
|
||||
if has_extensions {
|
||||
Some("--extension")
|
||||
} else {
|
||||
None
|
||||
},
|
||||
flags.profile.as_ref().map(|_| "--profile"),
|
||||
flags.state.as_ref().map(|_| "--state"),
|
||||
flags.args.as_ref().map(|_| "--args"),
|
||||
flags.user_agent.as_ref().map(|_| "--user-agent"),
|
||||
flags.proxy.as_ref().map(|_| "--proxy"),
|
||||
@@ -356,7 +367,10 @@ fn main() {
|
||||
|
||||
let err = match send_command(launch_cmd, &flags.session) {
|
||||
Ok(resp) if resp.success => None,
|
||||
Ok(resp) => Some(resp.error.unwrap_or_else(|| "Provider connection failed".to_string())),
|
||||
Ok(resp) => Some(
|
||||
resp.error
|
||||
.unwrap_or_else(|| "Provider connection failed".to_string()),
|
||||
),
|
||||
Err(e) => Some(e.to_string()),
|
||||
};
|
||||
|
||||
@@ -371,14 +385,23 @@ fn main() {
|
||||
}
|
||||
|
||||
// Launch headed browser or configure browser options (without CDP or provider)
|
||||
if (flags.headed || flags.profile.is_some() || flags.proxy.is_some() || flags.args.is_some() || flags.user_agent.is_some()) && flags.cdp.is_none() && flags.provider.is_none() {
|
||||
if (flags.headed
|
||||
|| flags.profile.is_some()
|
||||
|| flags.state.is_some()
|
||||
|| flags.proxy.is_some()
|
||||
|| flags.args.is_some()
|
||||
|| flags.user_agent.is_some())
|
||||
&& flags.cdp.is_none()
|
||||
&& flags.provider.is_none()
|
||||
{
|
||||
let mut launch_cmd = json!({
|
||||
"id": gen_id(),
|
||||
"action": "launch",
|
||||
"headless": !flags.headed
|
||||
});
|
||||
|
||||
let cmd_obj = launch_cmd.as_object_mut()
|
||||
let cmd_obj = launch_cmd
|
||||
.as_object_mut()
|
||||
.expect("json! macro guarantees object type");
|
||||
|
||||
// Add profile path if specified
|
||||
@@ -386,6 +409,11 @@ fn main() {
|
||||
cmd_obj.insert("profile".to_string(), json!(profile_path));
|
||||
}
|
||||
|
||||
// Add state path if specified
|
||||
if let Some(ref state_path) = flags.state {
|
||||
cmd_obj.insert("storageState".to_string(), json!(state_path));
|
||||
}
|
||||
|
||||
if let Some(ref proxy_str) = flags.proxy {
|
||||
let mut proxy_obj = parse_proxy(proxy_str);
|
||||
// Add bypass if specified
|
||||
@@ -417,7 +445,11 @@ fn main() {
|
||||
|
||||
if let Err(e) = send_command(launch_cmd, &flags.session) {
|
||||
if !flags.json {
|
||||
eprintln!("{} Could not configure browser: {}", color::warning_indicator(), e);
|
||||
eprintln!(
|
||||
"{} Could not configure browser: {}",
|
||||
color::warning_indicator(),
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -426,9 +458,7 @@ fn main() {
|
||||
Ok(resp) => {
|
||||
let success = resp.success;
|
||||
// Extract action for context-specific output handling
|
||||
let action = cmd
|
||||
.get("action")
|
||||
.and_then(|v| v.as_str());
|
||||
let action = cmd.get("action").and_then(|v| v.as_str());
|
||||
print_response(&resp, flags.json, action);
|
||||
if !success {
|
||||
exit(1);
|
||||
|
||||
Reference in New Issue
Block a user