Skip to content
Merged
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
7 changes: 5 additions & 2 deletions docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@ steel browser start

### Parameters

- `--stealth` (boolean, optional): Enable stealth mode (humanize interactions + auto CAPTCHA)
- `-p, --proxy` (string, optional): Use a residential proxy
- `--stealth` (boolean, optional): Enable stealth mode: humanized interactions, plus automatic CAPTCHA solving when your plan includes it
- `-p, --proxy` (string, optional): Route the session through your own proxy (http://user:pass@host:port)
- `--use-proxy` (boolean, optional): Use a Steel-managed residential proxy
- `--project` (string, optional): Project to create the session in, needed with an organization-wide API key. Defaults to STEEL_PROJECT_ID
- `--timeout` (string, optional): Session timeout in milliseconds. Defaults to 900000 (15 minutes), which every plan allows (create-time only)
- `--inactivity-timeout` (string, optional): Inactivity timeout in milliseconds: release the session when no command, CDP message, or remote input arrives for this long. Defaults to 600000 (10 minutes); pass 0 to disable (create-time only)
- `--solve-captcha` (boolean, optional): Enable manual CAPTCHA solving on new sessions (create-time only)
Expand Down Expand Up @@ -1283,6 +1285,7 @@ steel init
### Parameters

- `--agent` (boolean, optional): Run in agent mode: auto-accept interactive prompts and print agent-friendly output. Designed for AI coding agents
- `--from` (string, optional): Coding client for targeted agent setup (opencode, claude-code, codex, pi)
- `--skills` (string[], optional): Open the Steel skills installer flow. With no value, lets you choose skills interactively
- `--no-skills` (boolean, optional): Skip Steel skill installation

Expand Down
15 changes: 13 additions & 2 deletions docs/references/steel-browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Main flags:
- `--session <name>`
- `--stealth`
- `--proxy <url>`
- `--use-proxy`
- `--project <id>`
- `--timeout <ms>`
- `--inactivity-timeout <ms>` (default 600000; `0` turns it off)
- `--solve-captcha`
Expand All @@ -52,11 +54,20 @@ Flag semantics:
- `stealthConfig.humanizeInteractions = true`
- `stealthConfig.autoCaptchaSolving = true`
- `solveCaptcha = true`
- If the plan refuses CAPTCHA solving (`plan_feature_unavailable` or
`deposit_required`), the session starts again without it and the output
carries a note in `data.notes`. Interactions are still humanized.
- `--solve-captcha` enables manual CAPTCHA solving for new sessions:
- `solveCaptcha = true`
- `stealthConfig.autoCaptchaSolving` is not forced on
- `--proxy <url>` sets `proxyUrl` on session creation. The Sessions API may return
`proxySource: "external"` rather than echoing the proxy URL in responses.
- If the plan refuses it, the command fails. It is never dropped.
- `--proxy <url>` sets `proxyUrl` on session creation (your own proxy). It must be
a URL. The Sessions API may return `proxySource: "external"` rather than
echoing the proxy URL in responses.
- `--use-proxy` sets `useProxy = true` (a Steel residential proxy).
`--proxy residential` is read the same way, with a note.
- `--project <id>` sets `projectId`. An organization-wide API key needs it.
`STEEL_PROJECT_ID` sets it when the flag is absent.
- `--namespace <name>` sets the credential namespace for the session. Credentials
stored under this namespace will be available for injection.
- `--credentials` enables credential injection for the session. Sends
Expand Down
9 changes: 9 additions & 0 deletions src/api/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ pub enum ApiError {
}

impl ApiError {
pub fn body_str(&self, key: &str) -> Option<&str> {
match self {
Self::RequestFailed {
body: Some(body), ..
} => body.get(key).and_then(Value::as_str),
_ => None,
}
}

/// Check if this is a 404/410 (not found). Matches TS `isNotFoundApiError()`.
pub const fn is_not_found(&self) -> bool {
matches!(self, Self::RequestFailed { status, .. } if *status == 404 || *status == 410)
Expand Down
46 changes: 44 additions & 2 deletions src/api/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ use crate::config::settings::ApiMode;
const CLOUD_CONNECT_URL: &str = "wss://connect.steel.dev";
const CLOUD_VIEWER_URL: &str = "https://app.steel.dev/sessions";

#[derive(Debug, Default)]
#[derive(Debug, Default, Clone)]
pub struct CreateSessionOptions {
pub stealth: bool,
pub stealth_without_captcha: bool,
pub proxy_url: Option<String>,
pub use_proxy: bool,
pub project_id: Option<String>,
pub timeout_ms: Option<u64>,
pub inactivity_timeout_ms: Option<u64>,
pub headless: Option<bool>,
Expand Down Expand Up @@ -131,14 +134,30 @@ fn build_create_body(options: &CreateSessionOptions) -> Value {
}
}

if options.stealth {
if options.stealth && options.stealth_without_captcha {
obj.insert(
"stealthConfig".into(),
json!({"humanizeInteractions": true}),
);
} else if options.stealth {
obj.insert(
"stealthConfig".into(),
json!({"humanizeInteractions": true, "autoCaptchaSolving": true}),
);
obj.insert("solveCaptcha".into(), json!(true));
}

if options.use_proxy {
obj.insert("useProxy".into(), json!(true));
}

if let Some(ref project_id) = options.project_id {
let trimmed = project_id.trim();
if !trimmed.is_empty() {
obj.insert("projectId".into(), json!(trimmed));
}
}

if options.solve_captcha {
obj.insert("solveCaptcha".into(), json!(true));
}
Expand Down Expand Up @@ -386,6 +405,29 @@ mod tests {
assert!(body["stealthConfig"].is_object());
}

#[test]
fn create_body_stealth_without_captcha_keeps_humanizing_only() {
let body = build_create_body(&CreateSessionOptions {
stealth: true,
stealth_without_captcha: true,
..Default::default()
});
assert_eq!(
body,
json!({"stealthConfig": {"humanizeInteractions": true}})
);
}

#[test]
fn create_body_steel_proxy_and_project() {
let body = build_create_body(&CreateSessionOptions {
use_proxy: true,
project_id: Some(" p-1 ".into()),
..Default::default()
});
assert_eq!(body, json!({"useProxy": true, "projectId": "p-1"}));
}

#[test]
fn create_body_all_fields() {
let body = build_create_body(&CreateSessionOptions {
Expand Down
122 changes: 114 additions & 8 deletions src/commands/browser/start.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::Parser;
use serde_json::json;

use crate::api::client::SteelClient;
use crate::api::client::{ApiError, SteelClient};
use crate::api::session::CreateSessionOptions;
use crate::browser::profile_store;
use crate::browser::state::{self, BrowserSession};
Expand All @@ -13,14 +13,22 @@ pub const DEFAULT_INACTIVITY_TIMEOUT_MS: u64 = 600_000;

#[derive(Parser)]
pub struct Args {
/// Enable stealth mode (humanize interactions + auto CAPTCHA)
/// Enable stealth mode: humanized interactions, plus automatic CAPTCHA solving when your plan includes it
#[arg(long)]
pub stealth: bool,

/// Use a residential proxy
#[arg(short = 'p', long)]
/// Route the session through your own proxy (http://user:pass@host:port)
#[arg(short = 'p', long, value_name = "URL", conflicts_with = "use_proxy")]
pub proxy: Option<String>,

/// Use a Steel-managed residential proxy
#[arg(long = "use-proxy")]
pub use_proxy: bool,

/// Project to create the session in, needed with an organization-wide API key. Defaults to STEEL_PROJECT_ID
#[arg(long, value_name = "ID")]
pub project: Option<String>,

/// Session timeout in milliseconds. Defaults to 900000 (15 minutes), which every plan allows (create-time only)
#[arg(long, alias = "session-timeout")]
pub timeout: Option<u64>,
Expand Down Expand Up @@ -66,10 +74,69 @@ pub fn default_options() -> CreateSessionOptions {
CreateSessionOptions {
timeout_ms: Some(DEFAULT_TIMEOUT_MS),
inactivity_timeout_ms: Some(DEFAULT_INACTIVITY_TIMEOUT_MS),
project_id: project_from_env(),
..Default::default()
}
}

fn project_from_env() -> Option<String> {
std::env::var("STEEL_PROJECT_ID")
.ok()
.filter(|value| !value.trim().is_empty())
}

#[derive(Debug, PartialEq, Eq)]
struct ProxyChoice {
url: Option<String>,
steel: bool,
aliased: bool,
}

const PROXY_URL_REQUIRED: &str = "--proxy takes a proxy URL such as http://user:pass@host:port. For a Steel residential proxy, use --use-proxy.";

fn resolve_proxy(proxy: Option<String>, use_proxy: bool) -> anyhow::Result<ProxyChoice> {
let Some(value) = proxy
.map(|value| value.trim().to_string())
.filter(|value| !value.is_empty())
else {
return Ok(ProxyChoice {
url: None,
steel: use_proxy,
aliased: false,
});
};
if value.eq_ignore_ascii_case("residential") || value.eq_ignore_ascii_case("steel") {
return Ok(ProxyChoice {
url: None,
steel: true,
aliased: true,
});
}
match url::Url::parse(&value) {
Ok(url) if url.has_host() => Ok(ProxyChoice {
url: Some(value),
steel: use_proxy,
aliased: false,
}),
_ => Err(invalid_input(PROXY_URL_REQUIRED)),
}
}

fn captcha_refusal(err: &anyhow::Error, options: &CreateSessionOptions) -> Option<&'static str> {
if !options.stealth || options.solve_captcha || options.stealth_without_captcha {
return None;
}
let api = err.downcast_ref::<ApiError>()?;
if api.body_str("param") != Some("solveCaptcha") {
return None;
}
match api.body_str("code")? {
"plan_feature_unavailable" => Some("your plan does not include CAPTCHA solving"),
"deposit_required" => Some("CAPTCHA solving needs a paid balance on your plan"),
_ => None,
}
}

fn now_ms() -> Option<u64> {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
Expand Down Expand Up @@ -109,6 +176,15 @@ pub async fn run(args: Args, session: Option<&str>) -> anyhow::Result<()> {
)));
}
let session_metadata = metadata::collect(args.metadata)?;
let proxy = resolve_proxy(args.proxy, args.use_proxy)?;
let mut notes = Vec::new();
if proxy.aliased {
notes.push(
"--proxy takes a proxy URL, so a Steel residential proxy (--use-proxy) is used instead."
.to_string(),
);
}
let project_id = args.project.or_else(project_from_env);

let mut resolved_profile_id = None;
let mut stored_browser_profile = None;
Expand All @@ -129,7 +205,7 @@ pub async fn run(args: Args, session: Option<&str>) -> anyhow::Result<()> {
}

let persist_profile = args.profile.is_some() && args.update_profile;
let proxy_enabled = args.proxy.is_some();
let proxy_enabled = proxy.url.is_some() || proxy.steel;
let namespace_set = args.namespace.is_some();
let metadata_set = !session_metadata.is_empty();
let timeout = args.timeout.unwrap_or(DEFAULT_TIMEOUT_MS);
Expand Down Expand Up @@ -166,7 +242,10 @@ pub async fn run(args: Args, session: Option<&str>) -> anyhow::Result<()> {

let options = CreateSessionOptions {
stealth: args.stealth,
proxy_url: args.proxy,
stealth_without_captcha: false,
proxy_url: proxy.url,
use_proxy: proxy.steel,
project_id: project_id.clone(),
timeout_ms: Some(timeout),
inactivity_timeout_ms,
headless: args.headless,
Expand All @@ -179,7 +258,24 @@ pub async fn run(args: Args, session: Option<&str>) -> anyhow::Result<()> {
metadata: session_metadata,
};

let (created, connect_url) = create(&client, &session_name, &options).await?;
let mut captcha_dropped = false;
let (created, connect_url) = match create(&client, &session_name, &options).await {
Ok(done) => done,
Err(err) => {
let Some(reason) = captcha_refusal(&err, &options) else {
return Err(err);
};
captcha_dropped = true;
notes.push(format!(
"Started without CAPTCHA solving because {reason}. Interactions are still humanized."
));
let without_captcha = CreateSessionOptions {
stealth_without_captcha: true,
..options.clone()
};
create(&client, &session_name, &without_captcha).await?
}
};

if let Some(ref profile_name) = args.profile
&& let Some(ref returned_profile_id) = created.profile_id
Expand All @@ -195,6 +291,9 @@ pub async fn run(args: Args, session: Option<&str>) -> anyhow::Result<()> {
let mut properties = serde_json::Map::new();
properties.insert("stealth".into(), json!(args.stealth));
properties.insert("proxy_enabled".into(), json!(proxy_enabled));
properties.insert("use_proxy".into(), json!(proxy.steel));
properties.insert("project_set".into(), json!(project_id.is_some()));
properties.insert("stealth_captcha_dropped".into(), json!(captcha_dropped));
properties.insert("has_profile".into(), json!(args.profile.is_some()));
properties.insert("persist_profile".into(), json!(persist_profile));
properties.insert("credentials".into(), json!(args.credentials));
Expand All @@ -204,7 +303,10 @@ pub async fn run(args: Args, session: Option<&str>) -> anyhow::Result<()> {
properties.insert("inactivity_timeout_ms".into(), json!(inactivity_timeout_ms));
crate::telemetry::track_event("browser_session_started", properties);

display_session_info(&created, connect_url.as_deref(), replaced.as_ref());
for note in &notes {
eprintln!("note: {note}");
}
display_session_info(&created, connect_url.as_deref(), replaced.as_ref(), &notes);

Ok(())
}
Expand All @@ -213,6 +315,7 @@ fn display_session_info(
info: &BrowserSession,
connect_url: Option<&str>,
replaced: Option<&(String, bool)>,
notes: &[String],
) {
let remaining = remaining_time_str(info);

Expand All @@ -238,6 +341,9 @@ fn display_session_info(
if let Some(ms) = info.inactivity_timeout_ms {
data["inactivityTimeoutMs"] = json!(ms);
}
if !notes.is_empty() {
data["notes"] = json!(notes);
}
output::success_data(data);
} else {
println!("id: {}", info.id);
Expand Down
13 changes: 12 additions & 1 deletion src/util/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,14 @@ const fn class(

const NETWORK_HINT: Option<&str> = Some("Check your network connection.");
const LOCAL_STATE_HINT: Option<&str> = Some("Delete the file and retry.");
const PROJECT_HINT: Option<&str> = Some(
"This API key covers the whole organization. Pass --project <project-id> to steel browser start, or set STEEL_PROJECT_ID.",
);
const LOGIN_HINT: Option<&str> = Some(
"If an agent runs this command, show the URL and code to the user and retry after they approve. STEEL_API_KEY also works.",
);

const fn classify_api(err: &crate::api::client::ApiError) -> ErrorClass {
fn classify_api(err: &crate::api::client::ApiError) -> ErrorClass {
use crate::api::client::ApiError;
match err {
ApiError::DeviceAuth(_) => class(
Expand All @@ -255,6 +258,14 @@ const fn classify_api(err: &crate::api::client::ApiError) -> ErrorClass {
"api_redirect_refused",
NETWORK_HINT,
),
ApiError::RequestFailed { .. } if err.body_str("code") == Some("project_required") => {
class(
exit_code::API_CLIENT,
"request_failed",
"api_request_failed",
PROJECT_HINT,
)
}
ApiError::RequestFailed { status, .. } => match *status {
401 => class(
exit_code::AUTH,
Expand Down
Loading