diff --git a/docs/references/steel-browser.md b/docs/references/steel-browser.md index 6b08b7b..1a557cd 100644 --- a/docs/references/steel-browser.md +++ b/docs/references/steel-browser.md @@ -57,6 +57,9 @@ Flag semantics: - 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. + - On `deposit_required`, the note carries the link to verify the account + (the API's `unlockUrl`). Pass it to your user: adding $10 of credits once + turns on CAPTCHA solving and Steel proxies. - `--solve-captcha` enables manual CAPTCHA solving for new sessions: - `solveCaptcha = true` - `stealthConfig.autoCaptchaSolving` is not forced on diff --git a/src/commands/browser/start.rs b/src/commands/browser/start.rs index a6b38c1..43c7130 100644 --- a/src/commands/browser/start.rs +++ b/src/commands/browser/start.rs @@ -122,7 +122,9 @@ fn resolve_proxy(proxy: Option, use_proxy: bool) -> anyhow::Result Option<&'static str> { +const VERIFY_ACCOUNT_URL: &str = "https://app.steel.dev/overview?open=verify-account"; + +fn captcha_refusal(err: &anyhow::Error, options: &CreateSessionOptions) -> Option { if !options.stealth || options.solve_captcha || options.stealth_without_captcha { return None; } @@ -131,8 +133,16 @@ fn captcha_refusal(err: &anyhow::Error, options: &CreateSessionOptions) -> Optio 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"), + "plan_feature_unavailable" => Some( + "Started without CAPTCHA solving because your plan does not include CAPTCHA solving. Interactions are still humanized." + .to_string(), + ), + "deposit_required" => { + let url = api.body_str("unlockUrl").unwrap_or(VERIFY_ACCOUNT_URL); + Some(format!( + "Started without CAPTCHA solving because it needs a verified account on your plan. Interactions are still humanized. Tell your user: add $10 of credits once at {url} to turn on CAPTCHA solving." + )) + } _ => None, } } @@ -280,13 +290,11 @@ pub async fn run(args: Args, session: Option<&str>) -> anyhow::Result<()> { let (created, connect_url) = match create(&client, &session_name, &options).await { Ok(done) => done, Err(err) => { - let Some(reason) = captcha_refusal(&err, &options) else { + let Some(note) = captcha_refusal(&err, &options) else { return Err(err); }; captcha_dropped = true; - notes.push(format!( - "Started without CAPTCHA solving because {reason}. Interactions are still humanized." - )); + notes.push(note); let without_captcha = CreateSessionOptions { stealth_without_captcha: true, ..options.clone() diff --git a/tests/browser_commands.rs b/tests/browser_commands.rs index c05e956..249675c 100644 --- a/tests/browser_commands.rs +++ b/tests/browser_commands.rs @@ -850,15 +850,23 @@ async fn session_bodies(server: &MockServer) -> Vec { } async fn refuse_captcha(server: &MockServer, code: &str) { + refuse_captcha_with(server, code, None).await; +} + +async fn refuse_captcha_with(server: &MockServer, code: &str, unlock_url: Option<&str>) { + let mut body = json!({ + "error": "Bad Request", + "code": code, + "message": "Captcha solving is not available on the hobby plan.", + "param": "solveCaptcha" + }); + if let Some(url) = unlock_url { + body["unlockUrl"] = json!(url); + } Mock::given(method("POST")) .and(path("/v1/sessions")) .and(body_partial_json(json!({"solveCaptcha": true}))) - .respond_with(ResponseTemplate::new(400).set_body_json(json!({ - "error": "Bad Request", - "code": code, - "message": "Captcha solving is not available on the hobby plan.", - "param": "solveCaptcha" - }))) + .respond_with(ResponseTemplate::new(400).set_body_json(body)) .with_priority(1) .mount(server) .await; @@ -902,6 +910,45 @@ async fn stealth_starts_without_captcha_when_the_plan_refuses_it() { } } +#[tokio::test] +async fn a_dropped_captcha_points_to_verifying_the_account() { + let cases = [ + ( + Some("https://app.steel.dev/settings/billing?verify=1"), + "https://app.steel.dev/settings/billing?verify=1", + ), + (None, "https://app.steel.dev/overview?open=verify-account"), + ]; + for (unlock_url, expected) in cases { + let server = MockServer::start().await; + refuse_captcha_with(&server, "deposit_required", unlock_url).await; + accept_sessions(&server).await; + let cli = Cli::new(&server); + + let started = cli.run(&["browser", "start", "--stealth"]).await; + assert!(started.status.success(), "{started:?}"); + let note = json_out(&started)["data"]["notes"][0] + .as_str() + .unwrap() + .to_string(); + assert!(note.contains("Tell your user"), "{note}"); + assert!(note.contains(expected), "{note}"); + assert!(String::from_utf8_lossy(&started.stderr).contains(expected)); + } + + let server = MockServer::start().await; + refuse_captcha(&server, "plan_feature_unavailable").await; + accept_sessions(&server).await; + let cli = Cli::new(&server); + let started = cli.run(&["browser", "start", "--stealth"]).await; + assert!(started.status.success(), "{started:?}"); + let note = json_out(&started)["data"]["notes"][0] + .as_str() + .unwrap() + .to_string(); + assert!(!note.contains("verify-account"), "{note}"); +} + #[tokio::test] async fn an_explicit_captcha_request_is_never_dropped() { let server = MockServer::start().await;