diff --git a/README.md b/README.md index d86595e..452df5f 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,7 @@ flowchart TD ## Operational Recommendations - Prefer `--headed` for high-friction targets. -- Reuse session state with one stable `--session-name` for continuity (when omitted, it defaults to `--session`). +- Reuse session state with one stable `--session-name` for continuity (when omitted, it defaults to `default`). - Keep locale/timezone consistent with target market. - For challenge-heavy pages, prefer `--wait-until domcontentloaded` on `open`/`navigate` to avoid `load` stalls. - Use `--risk-mode block` in strict pipelines that require explicit operator intervention on verification pages. diff --git a/cli/src/flags.rs b/cli/src/flags.rs index 1828e82..14725b8 100644 --- a/cli/src/flags.rs +++ b/cli/src/flags.rs @@ -1,4 +1,4 @@ -use crate::{color, validation}; +use crate::color; use serde::Deserialize; use std::env; use std::fs; @@ -214,7 +214,7 @@ pub struct Flags { pub allow_file_access: bool, pub device: Option, pub auto_connect: bool, - pub session_name: Option, // Defaults to --session when unset + pub session_name: Option, // Defaults to "default" when unset pub annotate: bool, pub color_scheme: Option, pub download_path: Option, @@ -273,10 +273,8 @@ pub fn parse_flags(args: &[String]) -> Flags { Err(_) => config.headed.unwrap_or(true), }, debug: env_var_is_truthy("AGENT_BROWSER_DEBUG") || config.debug.unwrap_or(false), - session: env::var("AGENT_BROWSER_SESSION") - .ok() - .or(config.session) - .unwrap_or_else(|| "default".to_string()), + // --session is disabled: user-facing CLI always uses one default session. + session: "default".to_string(), headers: config.headers, executable_path: env::var("AGENT_BROWSER_EXECUTABLE_PATH") .ok() @@ -368,12 +366,6 @@ pub fn parse_flags(args: &[String]) -> Flags { i += 1; } } - "--session" => { - if let Some(s) = args.get(i + 1) { - flags.session = s.clone(); - i += 1; - } - } "--headers" => { if let Some(h) = args.get(i + 1) { flags.headers = Some(h.clone()); @@ -532,14 +524,9 @@ pub fn parse_flags(args: &[String]) -> Flags { } // Keep auth/state continuity stable by default: if no explicit --session-name - // is provided, derive it from --session (or fall back to "default" when invalid). + // is provided, derive it from the default session id. if flags.session_name.is_none() { - let derived = if validation::is_valid_session_name(&flags.session) { - flags.session.clone() - } else { - "default".to_string() - }; - flags.session_name = Some(derived); + flags.session_name = Some("default".to_string()); } flags @@ -753,27 +740,36 @@ mod tests { } #[test] - fn test_parse_flags_with_session_and_executable_path() { + fn test_parse_flags_ignores_session_flag_and_keeps_default_session() { let flags = parse_flags(&args( "--session test --executable-path /custom/chrome open example.com", )); - assert_eq!(flags.session, "test"); + assert_eq!(flags.session, "default"); assert_eq!(flags.executable_path, Some("/custom/chrome".to_string())); - assert_eq!(flags.session_name.as_deref(), Some("test")); + assert_eq!(flags.session_name.as_deref(), Some("default")); } #[test] - fn test_session_name_defaults_to_session_when_not_provided() { + fn test_session_name_defaults_to_default_when_not_provided() { let flags = parse_flags(&args("--session my-session snapshot")); - assert_eq!(flags.session_name.as_deref(), Some("my-session")); + assert_eq!(flags.session_name.as_deref(), Some("default")); } #[test] - fn test_invalid_session_falls_back_to_default_session_name() { + fn test_invalid_session_still_uses_default_session_name() { let flags = parse_flags(&args("--session bad/session snapshot")); assert_eq!(flags.session_name.as_deref(), Some("default")); } + #[test] + fn test_env_session_is_ignored_and_default_session_is_used() { + let _guard = EnvGuard::new(&["AGENT_BROWSER_SESSION"]); + env::set_var("AGENT_BROWSER_SESSION", "legacy-session"); + let flags = parse_flags(&args("snapshot")); + assert_eq!(flags.session, "default"); + assert_eq!(flags.session_name.as_deref(), Some("default")); + } + #[test] fn test_cli_executable_path_tracking() { // When --executable-path is passed via CLI, cli_executable_path should be true diff --git a/cli/src/output.rs b/cli/src/output.rs index 986ba8f..af1ea85 100644 --- a/cli/src/output.rs +++ b/cli/src/output.rs @@ -871,7 +871,6 @@ Aliases: goto, navigate Global Options: --json Output as JSON - --session Use specific session --headers Set HTTP headers (scoped to this origin) --risk-mode Risk handling for verify/captcha pages: off, warn, block --wait-until Navigation wait strategy: load, domcontentloaded, networkidle @@ -898,7 +897,6 @@ the browser's back button. Global Options: --json Output as JSON - --session Use specific session Examples: agent-browser back @@ -915,7 +913,6 @@ the browser's forward button. Global Options: --json Output as JSON - --session Use specific session Examples: agent-browser forward @@ -932,7 +929,6 @@ the browser's reload button. Global Options: --json Output as JSON - --session Use specific session Examples: agent-browser reload @@ -955,7 +951,6 @@ Options: Global Options: --json Output as JSON - --session Use specific session Examples: agent-browser click "#submit-button" @@ -976,7 +971,6 @@ or triggering double-click handlers. Global Options: --json Output as JSON - --session Use specific session Examples: agent-browser dblclick "#editable-text" @@ -994,7 +988,6 @@ This replaces any existing content in the field. Global Options: --json Output as JSON - --session Use specific session Examples: agent-browser fill "#email" "user@example.com" @@ -1014,7 +1007,6 @@ Use --delay to add per-character delay (milliseconds). Global Options: --json Output as JSON - --session Use specific session Examples: agent-browser type "#search" "hello" @@ -1039,7 +1031,6 @@ triggering hover states or dropdown menus. Global Options: --json Output as JSON - --session Use specific session Examples: agent-browser hover "#dropdown-trigger" @@ -1056,7 +1047,6 @@ Sets keyboard focus to the specified element. Global Options: --json Output as JSON - --session Use specific session Examples: agent-browser focus "#input-field" @@ -1073,7 +1063,6 @@ Checks a checkbox element. If already checked, no action is taken. Global Options: --json Output as JSON - --session Use specific session Examples: agent-browser check "#terms-checkbox" @@ -1090,7 +1079,6 @@ Unchecks a checkbox element. If already unchecked, no action is taken. Global Options: --json Output as JSON - --session Use specific session Examples: agent-browser uncheck "#newsletter-opt-in" @@ -1107,7 +1095,6 @@ Selects one or more options in a