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
3 changes: 3 additions & 0 deletions docs/references/steel-browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 15 additions & 7 deletions src/commands/browser/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ fn resolve_proxy(proxy: Option<String>, use_proxy: bool) -> anyhow::Result<Proxy
}
}

fn captcha_refusal(err: &anyhow::Error, options: &CreateSessionOptions) -> 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<String> {
if !options.stealth || options.solve_captcha || options.stealth_without_captcha {
return None;
}
Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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()
Expand Down
59 changes: 53 additions & 6 deletions tests/browser_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,15 +850,23 @@ async fn session_bodies(server: &MockServer) -> Vec<Value> {
}

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;
Expand Down Expand Up @@ -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;
Expand Down
Loading