Skip to content

Commit 128193c

Browse files
2c67cc18oai-codex
andcommitted
feat: add macOS-only native no-activate launch option
Co-authored-by: OpenAI Codex <codex@openai.com>
1 parent 4174284 commit 128193c

File tree

9 files changed

+517
-104
lines changed

9 files changed

+517
-104
lines changed

cli/src/commands.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,7 @@ mod tests {
20892089
json: false,
20902090
full: false,
20912091
headed: false,
2092+
no_activate: false,
20922093
debug: false,
20932094
headers: None,
20942095
executable_path: None,

cli/src/connection.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ pub struct DaemonResult {
215215
/// The daemon only needs `confirm_actions` to gate action categories.
216216
pub struct DaemonOptions<'a> {
217217
pub headed: bool,
218+
pub no_activate: bool,
218219
pub debug: bool,
219220
pub executable_path: Option<&'a str>,
220221
pub extensions: &'a [String],
@@ -244,6 +245,9 @@ fn apply_daemon_env(cmd: &mut Command, session: &str, opts: &DaemonOptions) {
244245
if opts.headed {
245246
cmd.env("AGENT_BROWSER_HEADED", "1");
246247
}
248+
if opts.no_activate {
249+
cmd.env("AGENT_BROWSER_NO_ACTIVATE", "1");
250+
}
247251
if opts.debug {
248252
cmd.env("AGENT_BROWSER_DEBUG", "1");
249253
}

cli/src/flags.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const PROJECT_CONFIG_FILENAME: &str = "agent-browser.json";
1212
#[serde(default, rename_all = "camelCase")]
1313
pub struct Config {
1414
pub headed: Option<bool>,
15+
pub no_activate: Option<bool>,
1516
pub json: Option<bool>,
1617
pub full: Option<bool>,
1718
pub debug: Option<bool>,
@@ -49,6 +50,7 @@ impl Config {
4950
fn merge(self, other: Config) -> Config {
5051
Config {
5152
headed: other.headed.or(self.headed),
53+
no_activate: other.no_activate.or(self.no_activate),
5254
json: other.json.or(self.json),
5355
full: other.full.or(self.full),
5456
debug: other.debug.or(self.debug),
@@ -211,6 +213,7 @@ pub struct Flags {
211213
pub json: bool,
212214
pub full: bool,
213215
pub headed: bool,
216+
pub no_activate: bool,
214217
pub debug: bool,
215218
pub session: String,
216219
pub headers: Option<String>,
@@ -283,6 +286,8 @@ pub fn parse_flags(args: &[String]) -> Flags {
283286
json: env_var_is_truthy("AGENT_BROWSER_JSON") || config.json.unwrap_or(false),
284287
full: env_var_is_truthy("AGENT_BROWSER_FULL") || config.full.unwrap_or(false),
285288
headed: env_var_is_truthy("AGENT_BROWSER_HEADED") || config.headed.unwrap_or(false),
289+
no_activate: env_var_is_truthy("AGENT_BROWSER_NO_ACTIVATE")
290+
|| config.no_activate.unwrap_or(false),
286291
debug: env_var_is_truthy("AGENT_BROWSER_DEBUG") || config.debug.unwrap_or(false),
287292
session: env::var("AGENT_BROWSER_SESSION")
288293
.ok()
@@ -385,6 +390,13 @@ pub fn parse_flags(args: &[String]) -> Flags {
385390
i += 1;
386391
}
387392
}
393+
"--no-activate" => {
394+
let (val, consumed) = parse_bool_arg(args, i);
395+
flags.no_activate = val;
396+
if consumed {
397+
i += 1;
398+
}
399+
}
388400
"--debug" => {
389401
let (val, consumed) = parse_bool_arg(args, i);
390402
flags.debug = val;
@@ -606,6 +618,7 @@ pub fn clean_args(args: &[String]) -> Vec<String> {
606618
"--json",
607619
"--full",
608620
"--headed",
621+
"--no-activate",
609622
"--debug",
610623
"--ignore-https-errors",
611624
"--allow-file-access",
@@ -1113,6 +1126,12 @@ mod tests {
11131126
assert!(flags.headed);
11141127
}
11151128

1129+
#[test]
1130+
fn test_no_activate_bare_defaults_true() {
1131+
let flags = parse_flags(&args("--no-activate open example.com"));
1132+
assert!(flags.no_activate);
1133+
}
1134+
11161135
#[test]
11171136
fn test_debug_false() {
11181137
let flags = parse_flags(&args("--debug false open example.com"));
@@ -1186,6 +1205,12 @@ mod tests {
11861205
assert_eq!(cleaned, vec!["open", "example.com"]);
11871206
}
11881207

1208+
#[test]
1209+
fn test_clean_args_removes_no_activate() {
1210+
let cleaned = clean_args(&args("--no-activate open example.com"));
1211+
assert_eq!(cleaned, vec!["open", "example.com"]);
1212+
}
1213+
11891214
// === Extensions merge tests ===
11901215

11911216
#[test]

cli/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ fn main() {
398398

399399
let daemon_opts = DaemonOptions {
400400
headed: flags.headed,
401+
no_activate: flags.no_activate,
401402
debug: flags.debug,
402403
executable_path: flags.executable_path.as_deref(),
403404
extensions: &flags.extensions,

cli/src/native/actions.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,9 @@ fn launch_options_from_env() -> LaunchOptions {
767767

768768
LaunchOptions {
769769
headless: !headed,
770+
no_activate: env::var("AGENT_BROWSER_NO_ACTIVATE")
771+
.map(|v| v == "1" || v == "true")
772+
.unwrap_or(false),
770773
executable_path: env::var("AGENT_BROWSER_EXECUTABLE_PATH").ok(),
771774
proxy: env::var("AGENT_BROWSER_PROXY").ok(),
772775
proxy_bypass: env::var("AGENT_BROWSER_PROXY_BYPASS").ok(),
@@ -939,6 +942,15 @@ async fn handle_launch(cmd: &Value, state: &mut DaemonState) -> Result<Value, St
939942

940943
let options = LaunchOptions {
941944
headless,
945+
no_activate: cmd
946+
.get("noActivate")
947+
.and_then(|v| v.as_bool())
948+
.or_else(|| {
949+
env::var("AGENT_BROWSER_NO_ACTIVATE")
950+
.ok()
951+
.map(|v| v == "1" || v == "true")
952+
})
953+
.unwrap_or(false),
942954
executable_path: cmd
943955
.get("executablePath")
944956
.and_then(|v| v.as_str())

cli/src/native/browser.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ fn validate_lightpanda_options(options: &LaunchOptions) -> Result<(), String> {
8383
"Custom Chrome arguments (--args) are not supported with Lightpanda".to_string(),
8484
);
8585
}
86+
if options.no_activate {
87+
return Err("--no-activate is only supported with native Chrome on macOS".to_string());
88+
}
8689
Ok(())
8790
}
8891

0 commit comments

Comments
 (0)