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
52 changes: 26 additions & 26 deletions docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ steel scrape

- `url` (string, optional): Target URL to scrape
- `--format` (string, optional): Comma-separated output formats: html, readability, cleaned_html, markdown
- `-d, --delay` (string, optional): Delay before scraping in milliseconds
- `-d, --delay` (integer, optional): Delay before scraping in milliseconds
- `--pdf` (boolean, optional): Include a generated PDF in the response
- `--screenshot` (boolean, optional): Include a generated screenshot in the response
- `--use-proxy` (boolean, optional): Use a Steel-managed residential proxy
Expand All @@ -149,7 +149,7 @@ steel screenshot
### Parameters

- `url` (string, optional): Target URL to capture
- `-d, --delay` (string, optional): Delay before capturing in milliseconds
- `-d, --delay` (integer, optional): Delay before capturing in milliseconds
- `-f, --full-page` (boolean, optional): Capture a full-page screenshot
- `--use-proxy` (boolean, optional): Use a Steel-managed residential proxy
- `-r, --region` (string, optional): Region identifier for request execution
Expand All @@ -167,7 +167,7 @@ steel pdf
### Parameters

- `url` (string, optional): Target URL to generate PDF from
- `-d, --delay` (string, optional): Delay before generating in milliseconds
- `-d, --delay` (integer, optional): Delay before generating in milliseconds
- `--use-proxy` (boolean, optional): Use a Steel-managed residential proxy
- `-r, --region` (string, optional): Region identifier for request execution

Expand Down Expand Up @@ -240,8 +240,8 @@ steel browser start
- `-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)
- `--timeout` (integer, optional): Session timeout in milliseconds. Defaults to 900000 (15 minutes), which every plan allows (create-time only)
- `--inactivity-timeout` (integer, 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)
- `--profile` (string, optional): Named profile to load (see `steel profile list`)
- `--update-profile` (boolean, optional): Save session state back to the profile when the session ends; creates the profile if it does not exist
Expand Down Expand Up @@ -330,8 +330,8 @@ steel browser captcha status

- `--page-id` (string, optional): Check only this page
- `-w, --wait` (boolean, optional): Wait for terminal status
- `--timeout` (string, optional): Timeout in milliseconds for --wait mode
- `--interval` (string, optional): Poll interval in milliseconds for --wait mode
- `--timeout` (integer, optional): Timeout in milliseconds for --wait mode
- `--interval` (integer, optional): Poll interval in milliseconds for --wait mode

## steel browser batch

Expand Down Expand Up @@ -407,7 +407,7 @@ steel browser click
### Parameters

- `selector` (string, required): Element ref (e.g. e5) or CSS selector
- `--count` (string, optional): Number of clicks (2 for double-click)
- `--count` (integer, optional): Number of clicks (2 for double-click)

## steel browser dblclick

Expand Down Expand Up @@ -453,7 +453,7 @@ steel browser type
- `selector` (string, required): Element ref or CSS selector
- `text` (string[], optional): Text to type
- `--clear` (boolean, optional): Clear the field before typing
- `--delay` (string, optional): Delay between keystrokes in milliseconds (at most 1000)
- `--delay` (integer, optional): Delay between keystrokes in milliseconds (at most 1000)

## steel browser press

Expand Down Expand Up @@ -611,7 +611,7 @@ steel browser scroll
### Parameters

- `direction` (enum, optional): Direction: up, down, left, right (default: down)
- `amount` (string, optional): Scroll amount in pixels (default: 300)
- `amount` (number, optional): Scroll amount in pixels (default: 300)
- `-s, --selector` (string, optional): Element to scroll instead of the page

## steel browser drag
Expand Down Expand Up @@ -657,12 +657,12 @@ steel browser mouse
### Parameters

- `action` (enum, required): move, down, up, click, or wheel
- `x` (string, optional): X in CSS pixels of the visible page (needed for move, click, and wheel)
- `y` (string, optional): Y in CSS pixels of the visible page (needed for move, click, and wheel)
- `x` (number, optional): X in CSS pixels of the visible page (needed for move, click, and wheel)
- `y` (number, optional): Y in CSS pixels of the visible page (needed for move, click, and wheel)
- `--button` (enum, optional): Mouse button: left, right, middle
- `--clicks` (string, optional): Click count for click (1 to 3)
- `--dx` (string, optional): Horizontal wheel delta
- `--dy` (string, optional): Vertical wheel delta
- `--clicks` (integer, optional): Click count for click (1 to 3)
- `--dx` (number, optional): Horizontal wheel delta
- `--dy` (number, optional): Vertical wheel delta

## steel browser snapshot

Expand All @@ -678,7 +678,7 @@ steel browser snapshot

- `-i, --interactive` (boolean, optional): Show only interactive elements
- `-c, --compact` (boolean, optional): Keep only lines with refs or values, and their ancestors
- `-d, --max-depth` (string, optional): Maximum nesting depth
- `-d, --max-depth` (integer, optional): Maximum nesting depth

## steel browser screenshot

Expand All @@ -696,7 +696,7 @@ steel browser screenshot
- `-o, --output` (string, optional): Output file path
- `--selector` (string, optional): Capture one element (ref or CSS selector)
- `--format` (enum, optional): Image format: png, jpeg, webp (default: from the output extension)
- `--quality` (string, optional): JPEG/WebP quality (0-100)
- `--quality` (integer, optional): JPEG/WebP quality (0-100)

## steel browser pdf

Expand Down Expand Up @@ -727,7 +727,7 @@ steel browser eval
### Parameters

- `script` (string, required): JavaScript expression or function body; its value is printed
- `--timeout` (string, optional): Time limit in milliseconds (default 10000, at most 50000)
- `--timeout` (integer, optional): Time limit in milliseconds (default 10000, at most 50000)

## steel browser find

Expand Down Expand Up @@ -967,8 +967,8 @@ steel browser wait

### Parameters

- `ms` (string, optional): Fixed time to wait in milliseconds (at most 30000)
- `--timeout` (string, optional): Timeout in milliseconds (at most 50000)
- `ms` (integer, optional): Fixed time to wait in milliseconds (at most 30000)
- `--timeout` (integer, optional): Timeout in milliseconds (at most 50000)
- `-t, --text` (string, optional): Wait for text to appear on the page
- `--selector` (string, optional): Wait for an element (ref or CSS selector)
- `--state` (enum, optional): Element state: visible, hidden, attached, detached
Expand Down Expand Up @@ -1106,7 +1106,7 @@ steel sessions list

### Parameters

- `--limit` (string, optional): Number of sessions to return
- `--limit` (integer, optional): Number of sessions to return
- `--cursor-id` (string, optional): Cursor ID for pagination
- `--status` (string, optional): Filter by status: live, released, or failed
- `--metadata` (string[], optional): Filter by metadata KEY=VALUE, repeatable; all must match
Expand Down Expand Up @@ -1209,8 +1209,8 @@ steel sessions logs
- `--since` (string, optional): Alias for --start-time
- `--end-time` (string, optional): ISO timestamp upper bound
- `--event-type` (string[], optional): Event type filter, repeatable or comma-separated
- `--limit` (string, optional): Number of events to return
- `--offset` (string, optional): Pagination offset
- `--limit` (integer, optional): Number of events to return
- `--offset` (integer, optional): Pagination offset

### API Operations

Expand All @@ -1237,8 +1237,8 @@ steel sessions agent-logs
- `--since` (string, optional): Alias for --start-time
- `--end-time` (string, optional): ISO timestamp upper bound
- `--event-type` (string[], optional): Event type filter, repeatable or comma-separated
- `--limit` (string, optional): Number of events to return
- `--offset` (string, optional): Pagination offset
- `--limit` (integer, optional): Number of events to return
- `--offset` (integer, optional): Pagination offset

### API Operations

Expand Down Expand Up @@ -1449,7 +1449,7 @@ steel dev start

### Parameters

- `-p, --port` (string, optional): API port for local Steel Browser runtime
- `-p, --port` (integer, optional): API port for local Steel Browser runtime
- `-V, --verbose` (boolean, optional): Enable verbose Docker command output
- `-d, --docker-check` (boolean, optional): Only verify Docker availability and exit

Expand Down
12 changes: 5 additions & 7 deletions src/commands/browser/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,10 +1235,7 @@ impl Browser {
let signs_in = match &target {
Some(Target::Saved(found)) => found.mode == ApiMode::Cloud,
Some(Target::Id(_)) => true,
None if name.is_none() && start_default => {
eprintln!("warning: session \"default\" is not running; starting a new one");
true
}
None if name.is_none() && start_default => true,
None => return Err(super::not_running(name)),
};
if signs_in {
Expand All @@ -1249,9 +1246,10 @@ impl Browser {
Some(Target::Saved(found)) => *found,
Some(Target::Id(id)) => attach(&client, &id).await?,
None => {
start::create(&client, DEFAULT_SESSION, &start::default_options())
.await?
.0
let (created, _) =
start::create(&client, DEFAULT_SESSION, &start::default_options()).await?;
eprintln!("note: {}", start::started_note(&created));
created
}
};
let client = client.at(&state.api_url, state.mode);
Expand Down
34 changes: 27 additions & 7 deletions src/commands/browser/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,24 @@ pub async fn create(
Ok((created, session.connect_url(mode, client.auth())))
}

pub fn started_note(info: &BrowserSession) -> String {
let span = |ms: u64| humanize_secs(ms / 1000);
let ends = match (info.timeout_ms, info.inactivity_timeout_ms) {
(Some(total), Some(idle)) => format!(
" It ends after {}, or after {} without commands.",
span(total),
span(idle)
),
(Some(total), None) => format!(" It ends after {}.", span(total)),
(None, Some(idle)) => format!(" It ends after {} without commands.", span(idle)),
(None, None) => String::new(),
};
format!(
"started session \"{}\".{ends} Stop it with `steel browser stop`.",
info.name
)
}

pub async fn run(args: Args, session: Option<&str>) -> anyhow::Result<()> {
let session_name = session.unwrap_or("default").to_string();
if state::looks_like_session_id(&session_name) {
Expand Down Expand Up @@ -381,12 +399,12 @@ fn remaining_time_str(info: &BrowserSession) -> Option<(u64, String)> {
}

fn humanize_secs(secs: u64) -> String {
if secs >= 3600 {
format!("{}h {}m", secs / 3600, (secs % 3600) / 60)
} else if secs >= 60 {
format!("{}m {}s", secs / 60, secs % 60)
} else {
format!("{secs}s")
match (secs / 3600, (secs % 3600) / 60, secs % 60) {
(0, 0, s) => format!("{s}s"),
(0, m, 0) => format!("{m}m"),
(0, m, s) => format!("{m}m {s}s"),
(h, 0, _) => format!("{h}h"),
(h, m, _) => format!("{h}h {m}m"),
}
}

Expand Down Expand Up @@ -493,7 +511,9 @@ mod tests {
#[test]
fn humanize_secs_formats() {
assert_eq!(humanize_secs(45), "45s");
assert_eq!(humanize_secs(120), "2m 0s");
assert_eq!(humanize_secs(120), "2m");
assert_eq!(humanize_secs(125), "2m 5s");
assert_eq!(humanize_secs(3600), "1h");
assert_eq!(humanize_secs(3661), "1h 1m");
}
}
47 changes: 46 additions & 1 deletion src/commands/describe.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::any::TypeId;

use crate::util::output;
use anyhow::{Result, bail};
use clap::{ArgAction, CommandFactory, Parser};
Expand Down Expand Up @@ -377,13 +379,33 @@ fn infer_type(arg: &clap::Arg) -> String {
if !possible.is_empty() {
"enum".into()
} else {
"string".into()
scalar_type(arg).into()
}
}
_ => "string".into(),
}
}

fn scalar_type(arg: &clap::Arg) -> &'static str {
let id = arg.get_value_parser().type_id();
let is_any = |types: &[TypeId]| types.iter().any(|t| id == *t);
if is_any(&[
TypeId::of::<u8>(),
TypeId::of::<u16>(),
TypeId::of::<u32>(),
TypeId::of::<u64>(),
TypeId::of::<usize>(),
TypeId::of::<i32>(),
TypeId::of::<i64>(),
]) {
"integer"
} else if is_any(&[TypeId::of::<f32>(), TypeId::of::<f64>()]) {
"number"
} else {
"string"
}
}

// ── Helpers ─────────────────────────────────────────────────────────

fn get_aliases(cmd: &clap::Command) -> Vec<String> {
Expand Down Expand Up @@ -635,6 +657,29 @@ mod tests {
assert_eq!(timeout["default"], "30000");
}

#[test]
fn numeric_args_typed_as_numbers() {
let param_type = |path: &[&str], name: &str| {
let v = describe_path(path);
v["parameters"]
.as_array()
.unwrap()
.iter()
.find(|p| p["name"] == name)
.unwrap()["type"]
.clone()
};
assert_eq!(param_type(&["browser", "start"], "timeout"), "integer");
assert_eq!(
param_type(&["browser", "start"], "inactivity-timeout"),
"integer"
);
assert_eq!(param_type(&["browser", "wait"], "timeout"), "integer");
assert_eq!(param_type(&["browser", "click"], "count"), "integer");
assert_eq!(param_type(&["browser", "scroll"], "amount"), "number");
assert_eq!(param_type(&["browser", "wait"], "text"), "string");
}

#[test]
fn vec_args_typed_as_array() {
let v = describe_path(&["browser", "fill"]);
Expand Down
13 changes: 11 additions & 2 deletions tests/browser_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,12 +742,14 @@ async fn screenshots_are_written_to_the_output_path() {
#[tokio::test]
async fn the_default_session_starts_on_first_use() {
let server = MockServer::start().await;
let mut created = session_json();
created["timeout"] = json!(900_000);
Mock::given(method("POST"))
.and(path("/v1/sessions"))
.and(body_partial_json(
json!({"timeout": 900_000, "inactivityTimeout": 600_000}),
))
.respond_with(ResponseTemplate::new(200).set_body_json(session_json()))
.respond_with(ResponseTemplate::new(200).set_body_json(created))
.expect(1)
.mount(&server)
.await;
Expand All @@ -766,7 +768,14 @@ async fn the_default_session_starts_on_first_use() {
.run(&["browser", "navigate", "https://example.com"])
.await;
assert!(out.status.success(), "{out:?}");
assert!(String::from_utf8_lossy(&out.stderr).contains("starting a new one"));
let err = String::from_utf8_lossy(&out.stderr);
assert!(
err.contains(
"note: started session \"default\". It ends after 15m, or after 10m without commands. Stop it with `steel browser stop`."
),
"{err}"
);
assert!(!err.contains("warning:"), "{err}");
assert_eq!(cli.state("default").unwrap()["next"], "op_1");
}

Expand Down
6 changes: 3 additions & 3 deletions tests/cli_blackbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,14 +615,14 @@ fn browser_action_with_missing_named_session_fails_without_starting_one() {
}

#[test]
fn browser_action_without_session_warns_before_starting_default() {
fn browser_action_without_session_notes_only_a_session_that_started() {
let output = run(&["--json", "browser", "navigate", "https://example.com"]);
assert!(!output.status.success());

let err = stderr(&output);
assert!(
err.contains("warning: session \"default\" is not running"),
"stderr should warn that a default session is being started, got: {err}"
!err.contains("started session") && !err.contains("warning:"),
"a failed start should not report a started session, got: {err}"
);
}

Expand Down
Loading