Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,7 @@ mod tests {
cli_proxy: false,
cli_proxy_bypass: false,
cli_allow_file_access: false,
cli_browser: false,
}
}

Expand Down
9 changes: 9 additions & 0 deletions cli/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ pub fn ensure_daemon(
provider: Option<&str>,
device: Option<&str>,
session_name: Option<&str>,
browser: Option<&str>,
) -> Result<DaemonResult, String> {
// Check if daemon is running AND responsive
if is_daemon_running(session) && daemon_ready(session) {
Expand Down Expand Up @@ -364,6 +365,10 @@ pub fn ensure_daemon(
cmd.env("AGENT_BROWSER_SESSION_NAME", sn);
}

if let Some(b) = browser {
cmd.env("AGENT_BROWSER_BROWSER", b);
}

// Create new process group and session to fully detach
unsafe {
cmd.pre_exec(|| {
Expand Down Expand Up @@ -447,6 +452,10 @@ pub fn ensure_daemon(
cmd.env("AGENT_BROWSER_SESSION_NAME", sn);
}

if let Some(b) = browser {
cmd.env("AGENT_BROWSER_BROWSER", b);
}

// CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS
const CREATE_NEW_PROCESS_GROUP: u32 = 0x00000200;
const DETACHED_PROCESS: u32 = 0x00000008;
Expand Down
12 changes: 12 additions & 0 deletions cli/src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Flags {
pub args: Option<String>,
pub user_agent: Option<String>,
pub provider: Option<String>,
pub browser: Option<String>,
pub ignore_https_errors: bool,
pub allow_file_access: bool,
pub device: Option<String>,
Expand All @@ -34,6 +35,7 @@ pub struct Flags {
pub cli_proxy: bool,
pub cli_proxy_bypass: bool,
pub cli_allow_file_access: bool,
pub cli_browser: bool,
}

pub fn parse_flags(args: &[String]) -> Flags {
Expand Down Expand Up @@ -64,6 +66,7 @@ pub fn parse_flags(args: &[String]) -> Flags {
args: env::var("AGENT_BROWSER_ARGS").ok(),
user_agent: env::var("AGENT_BROWSER_USER_AGENT").ok(),
provider: env::var("AGENT_BROWSER_PROVIDER").ok(),
browser: env::var("AGENT_BROWSER_BROWSER").ok(),
ignore_https_errors: false,
allow_file_access: env::var("AGENT_BROWSER_ALLOW_FILE_ACCESS").is_ok(),
device: env::var("AGENT_BROWSER_IOS_DEVICE").ok(),
Expand All @@ -79,6 +82,7 @@ pub fn parse_flags(args: &[String]) -> Flags {
cli_proxy: false,
cli_proxy_bypass: false,
cli_allow_file_access: false,
cli_browser: false,
};

let mut i = 0;
Expand Down Expand Up @@ -168,6 +172,13 @@ pub fn parse_flags(args: &[String]) -> Flags {
i += 1;
}
}
"--browser" => {
if let Some(b) = args.get(i + 1) {
flags.browser = Some(b.clone());
flags.cli_browser = true;
i += 1;
}
}
"--ignore-https-errors" => flags.ignore_https_errors = true,
"--allow-file-access" => {
flags.allow_file_access = true;
Expand Down Expand Up @@ -224,6 +235,7 @@ pub fn clean_args(args: &[String]) -> Vec<String> {
"--provider",
"--device",
"--session-name",
"--browser",
];

for arg in args.iter() {
Expand Down
6 changes: 6 additions & 0 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ fn main() {
flags.provider.as_deref(),
flags.device.as_deref(),
flags.session_name.as_deref(),
flags.browser.as_deref(),
) {
Ok(result) => result,
Err(e) => {
Expand Down Expand Up @@ -281,6 +282,11 @@ fn main() {
},
flags.ignore_https_errors.then_some("--ignore-https-errors"),
flags.cli_allow_file_access.then_some("--allow-file-access"),
if flags.cli_browser {
Some("--browser")
} else {
None
},
]
.into_iter()
.flatten()
Expand Down
13 changes: 9 additions & 4 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,18 +1144,23 @@ export class BrowserManager {
return;
}

const browserType = options.browser ?? 'chromium';
if (hasExtensions && browserType !== 'chromium') {
let effectiveBrowser = options.browser ?? 'chromium';
// Auto-fallback to Firefox on ARM64 Linux where Chromium is unavailable
if (effectiveBrowser === 'chromium' && process.arch === 'arm64' && process.platform === 'linux') {
effectiveBrowser = 'firefox';
this.launchWarnings.push('Chromium unavailable on ARM64 Linux; using Firefox instead');
}
if (hasExtensions && effectiveBrowser !== 'chromium') {
throw new Error('Extensions are only supported in Chromium');
}

// allowFileAccess is only supported in Chromium
if (options.allowFileAccess && browserType !== 'chromium') {
if (options.allowFileAccess && effectiveBrowser !== 'chromium') {
throw new Error('allowFileAccess is only supported in Chromium');
}

const launcher =
browserType === 'firefox' ? firefox : browserType === 'webkit' ? webkit : chromium;
effectiveBrowser === 'firefox' ? firefox : effectiveBrowser === 'webkit' ? webkit : chromium;
const viewport = options.viewport ?? { width: 1280, height: 720 };

// Build base args array with file access flags if enabled
Expand Down
2 changes: 2 additions & 0 deletions src/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ export async function startDaemon(options?: {

const ignoreHTTPSErrors = process.env.AGENT_BROWSER_IGNORE_HTTPS_ERRORS === '1';
const allowFileAccess = process.env.AGENT_BROWSER_ALLOW_FILE_ACCESS === '1';
const browserType = process.env.AGENT_BROWSER_BROWSER as 'chromium' | 'firefox' | 'webkit' | undefined;
await manager.launch({
id: 'auto',
action: 'launch' as const,
Expand All @@ -430,6 +431,7 @@ export async function startDaemon(options?: {
proxy,
ignoreHTTPSErrors: ignoreHTTPSErrors,
allowFileAccess: allowFileAccess,
browser: browserType,
autoStateFilePath: getSessionAutoStatePath(),
});
}
Expand Down