feat: add support for ignoring HTTPS certificate errors (#93)
* feat: add support for ignoring HTTPS certificate errors * fix: update warning message for already running daemon to include ignore HTTPS errors option * docs: add documentation for --ignore-https-errors option in README and SKILL.md * feat: initialize ignore_https_errors flag in command context * fix: change launch_cmd to mutable for cdp value handling
This commit is contained in:
@@ -1212,6 +1212,7 @@ mod tests {
|
||||
args: None,
|
||||
user_agent: None,
|
||||
provider: None,
|
||||
ignore_https_errors: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -194,6 +194,7 @@ pub fn ensure_daemon(
|
||||
user_agent: Option<&str>,
|
||||
proxy: Option<&str>,
|
||||
proxy_bypass: Option<&str>,
|
||||
ignore_https_errors: bool,
|
||||
) -> Result<DaemonResult, String> {
|
||||
if is_daemon_running(session) && daemon_ready(session) {
|
||||
return Ok(DaemonResult {
|
||||
@@ -266,6 +267,10 @@ pub fn ensure_daemon(
|
||||
cmd.env("AGENT_BROWSER_PROXY_BYPASS", pb);
|
||||
}
|
||||
|
||||
if ignore_https_errors {
|
||||
cmd.env("AGENT_BROWSER_IGNORE_HTTPS_ERRORS", "1");
|
||||
}
|
||||
|
||||
// Create new process group and session to fully detach
|
||||
unsafe {
|
||||
cmd.pre_exec(|| {
|
||||
@@ -321,6 +326,10 @@ pub fn ensure_daemon(
|
||||
cmd.env("AGENT_BROWSER_PROXY_BYPASS", pb);
|
||||
}
|
||||
|
||||
if ignore_https_errors {
|
||||
cmd.env("AGENT_BROWSER_IGNORE_HTTPS_ERRORS", "1");
|
||||
}
|
||||
|
||||
// CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS
|
||||
const CREATE_NEW_PROCESS_GROUP: u32 = 0x00000200;
|
||||
const DETACHED_PROCESS: u32 = 0x00000008;
|
||||
|
||||
+4
-1
@@ -16,6 +16,7 @@ pub struct Flags {
|
||||
pub args: Option<String>,
|
||||
pub user_agent: Option<String>,
|
||||
pub provider: Option<String>,
|
||||
pub ignore_https_errors: bool,
|
||||
}
|
||||
|
||||
pub fn parse_flags(args: &[String]) -> Flags {
|
||||
@@ -40,6 +41,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(),
|
||||
ignore_https_errors: false,
|
||||
};
|
||||
|
||||
let mut i = 0;
|
||||
@@ -115,6 +117,7 @@ pub fn parse_flags(args: &[String]) -> Flags {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
"--ignore-https-errors" => flags.ignore_https_errors = true,
|
||||
_ => {}
|
||||
}
|
||||
i += 1;
|
||||
@@ -127,7 +130,7 @@ pub fn clean_args(args: &[String]) -> Vec<String> {
|
||||
let mut skip_next = false;
|
||||
|
||||
// Global flags that should be stripped from command args
|
||||
const GLOBAL_FLAGS: &[&str] = &["--json", "--full", "--headed", "--debug"];
|
||||
const GLOBAL_FLAGS: &[&str] = &["--json", "--full", "--headed", "--debug", "--ignore-https-errors"];
|
||||
// Global flags that take a value (need to skip the next arg too)
|
||||
const GLOBAL_FLAGS_WITH_VALUE: &[&str] = &[
|
||||
"--session",
|
||||
|
||||
+15
-1
@@ -200,6 +200,7 @@ fn main() {
|
||||
flags.user_agent.as_deref(),
|
||||
flags.proxy.as_deref(),
|
||||
flags.proxy_bypass.as_deref(),
|
||||
flags.ignore_https_errors,
|
||||
) {
|
||||
Ok(result) => result,
|
||||
Err(e) => {
|
||||
@@ -223,6 +224,7 @@ fn main() {
|
||||
flags.user_agent.as_ref().map(|_| "--user-agent"),
|
||||
flags.proxy.as_ref().map(|_| "--proxy"),
|
||||
flags.proxy_bypass.as_ref().map(|_| "--proxy-bypass"),
|
||||
flags.ignore_https_errors.then(|| "--ignore-https-errors"),
|
||||
]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
@@ -235,6 +237,10 @@ fn main() {
|
||||
ignored_flags.join(", ")
|
||||
);
|
||||
}
|
||||
|
||||
if flags.ignore_https_errors {
|
||||
eprintln!("{} --ignore-https-errors ignored: daemon already running. Use 'agent-browser close' first to restart with this option.", color::warning_indicator());
|
||||
}
|
||||
}
|
||||
|
||||
// Validate mutually exclusive options
|
||||
@@ -261,7 +267,7 @@ fn main() {
|
||||
// Connect via CDP if --cdp flag is set
|
||||
// Accepts either a port number (e.g., "9222") or a full URL (e.g., "ws://..." or "wss://...")
|
||||
if let Some(ref cdp_value) = flags.cdp {
|
||||
let launch_cmd = if cdp_value.starts_with("ws://")
|
||||
let mut launch_cmd = if cdp_value.starts_with("ws://")
|
||||
|| cdp_value.starts_with("wss://")
|
||||
|| cdp_value.starts_with("http://")
|
||||
|| cdp_value.starts_with("https://")
|
||||
@@ -317,6 +323,10 @@ fn main() {
|
||||
})
|
||||
};
|
||||
|
||||
if flags.ignore_https_errors {
|
||||
launch_cmd["ignoreHTTPSErrors"] = json!(true);
|
||||
}
|
||||
|
||||
let err = match send_command(launch_cmd, &flags.session) {
|
||||
Ok(resp) if resp.success => None,
|
||||
Ok(resp) => Some(
|
||||
@@ -401,6 +411,10 @@ fn main() {
|
||||
cmd_obj.insert("args".to_string(), json!(args_vec));
|
||||
}
|
||||
|
||||
if flags.ignore_https_errors {
|
||||
launch_cmd["ignoreHTTPSErrors"] = json!(true);
|
||||
}
|
||||
|
||||
if let Err(e) = send_command(launch_cmd, &flags.session) {
|
||||
if !flags.json {
|
||||
eprintln!("{} Could not configure browser: {}", color::warning_indicator(), e);
|
||||
|
||||
@@ -1535,6 +1535,7 @@ Options:
|
||||
e.g., --proxy "http://user:pass@127.0.0.1:7890"
|
||||
--proxy-bypass <hosts> Bypass proxy for these hosts (or AGENT_BROWSER_PROXY_BYPASS)
|
||||
e.g., --proxy-bypass "localhost,*.internal.com"
|
||||
--ignore-https-errors Ignore HTTPS certificate errors
|
||||
-p, --provider <name> Cloud browser provider (or AGENT_BROWSER_PROVIDER env)
|
||||
--json JSON output
|
||||
--full, -f Full page screenshot
|
||||
|
||||
Reference in New Issue
Block a user