browser4-cli 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -133,7 +133,6 @@ The tables below mirror the commands surfaced by the global `browser4-cli help`
133
133
  | Command | Description |
134
134
  |---|---|
135
135
  | `screenshot [ref]` | Take a screenshot |
136
- | `pdf` | Save page as PDF |
137
136
 
138
137
  #### Tabs
139
138
 
@@ -146,6 +145,28 @@ The tables below mirror the commands surfaced by the global `browser4-cli help`
146
145
 
147
146
  Use `tab-list` first to find the zero-based tab index you want to select or close.
148
147
 
148
+ #### Browser storage
149
+
150
+ | Command | Description |
151
+ |---|---|
152
+ | `state-save <path>` | Save cookies and localStorage to a JSON file |
153
+ | `state-load <path>` | Restore cookies and localStorage from a saved state file |
154
+ | `cookie-list` | List all cookies (optionally filtered by `--domain` / `--path`) |
155
+ | `cookie-get <name>` | Get a cookie by name |
156
+ | `cookie-set <name> <value>` | Set a cookie (optional `--path`, `--domain`) |
157
+ | `cookie-delete <name>` | Delete a cookie by name |
158
+ | `cookie-clear` | Clear all cookies for the current page |
159
+ | `localstorage-list` | List all localStorage entries |
160
+ | `localstorage-get <key>` | Get a localStorage value by key |
161
+ | `localstorage-set <key> <value>` | Set a localStorage key-value pair |
162
+ | `localstorage-delete <key>` | Delete a localStorage key |
163
+ | `localstorage-clear` | Clear all localStorage entries |
164
+ | `sessionstorage-list` | List all sessionStorage entries |
165
+ | `sessionstorage-get <key>` | Get a sessionStorage value by key |
166
+ | `sessionstorage-set <key> <value>` | Set a sessionStorage key-value pair |
167
+ | `sessionstorage-delete <key>` | Delete a sessionStorage key |
168
+ | `sessionstorage-clear` | Clear all sessionStorage entries |
169
+
149
170
  #### Browser sessions
150
171
 
151
172
  | Command | Description |
@@ -156,6 +177,17 @@ Use `tab-list` first to find the zero-based tab index you want to select or clos
156
177
 
157
178
  Use `close-all` for session cleanup when you want to keep the current Browser4 service running. Use `kill-all` only when you explicitly want to stop the backend and clean up tracked Browser4 processes.
158
179
 
180
+ #### Server management
181
+
182
+ | Command | Description |
183
+ |---|---|
184
+ | `install` | Download the self-contained Browser4 runtime bundle (JAR + bundled JRE) from GitHub Releases |
185
+ | `upgrade` | Upgrade `browser4-cli` itself to the latest release (requires `cargo`) |
186
+ | `stop` | Kill the Browser4 backend after closing all sessions |
187
+ | `status` | Check whether the Browser4 backend is reachable and healthy |
188
+
189
+ When a local Browser4 checkout is detected with the `browser4-bundle` module present,
190
+ `install` auto-builds the runtime bundle from source instead of downloading.
159
191
 
160
192
  ### Advanced commands
161
193
 
@@ -164,18 +196,186 @@ Query `browser4-cli help <command>` for the exact syntax when you need them.
164
196
 
165
197
  | Command | Description |
166
198
  |---|---|
167
- | `batch [command...]` | Execute multiple commands in one invocation. Only DOM operations are supported (Core, Navigation, Keyboard, Mouse, Export, Tabs categories). Commands like `open`, `close`, `list`, `agent-run`, etc. are not allowed in batch mode. |
199
+ | `batch [command...]` | Execute multiple commands in one invocation. Only DOM operations are supported (Core, Navigation, Keyboard, Mouse, Export, Tabs categories). Commands like `open`, `close`, `list`, `agent run`, etc. are not allowed in batch mode. |
168
200
  | `console [min-level]` | List console messages |
169
201
  | `extract <instruction>` | Extract structured data from the current page |
170
202
  | `summarize [instruction]` | Summarize page content using AI |
171
- | `agent-run <task>` | Run an autonomous agent task |
172
- | `agent-status <id>` | Check the status of a running agent task |
173
- | `agent-result <id>` | Get the result of a completed agent task |
174
- | `co-create` | Create a collective session with parallel browser contexts |
175
- | `co-submit [url]` | Submit URL(s) or tasks to the active collective session |
176
- | `co-scrape <url>` | Scrape data from a URL using CSS selectors |
177
- | `co-status <id>` | Check the status of a collective task |
178
- | `co-result <id>` | Get the result of a completed collective task |
203
+ | `agent run <task>` | Run an autonomous agent task |
204
+ | `agent status <id>` | Check the status of a running agent task |
205
+ | `agent result <id>` | Get the result of a completed agent task |
206
+ | `swarm create` | Create a swarm scrape session with parallel browser contexts |
207
+ | `swarm submit [url]` | Submit URL(s) or X-SQL payloads as scrape jobs |
208
+ | `swarm status <id>` | Check the status of a scrape job |
209
+ | `swarm result <id>` | Get the result of a completed scrape job |
210
+
211
+ ## Agent task workflow (`agent <subcommand>`)
212
+
213
+ The `agent-*` commands wrap the backend command agent's asynchronous task API.
214
+ They are useful when you want Browser4 to plan and execute a natural-language
215
+ task in the background instead of issuing one low-level browser action at a
216
+ time.
217
+
218
+ Like other advanced commands, they are intentionally omitted from the global
219
+ `browser4-cli help` overview. Query `browser4-cli help agent run` (or
220
+ `agent status` / `agent result`) when you need the exact syntax.
221
+
222
+ Use the spaced `agent <subcommand>` form:
223
+
224
+ ```shell
225
+ browser4-cli agent run "Open example.com and summarize the hero section"
226
+ browser4-cli agent status agent-task-1
227
+ browser4-cli agent result agent-task-1
228
+ ```
229
+
230
+ ### Command lifecycle
231
+
232
+ | Step | Command | What it does |
233
+ |---|---|---|
234
+ | 1 | `agent run <task>` | Submits an asynchronous natural-language task through `command_run` and prints the returned task ID |
235
+ | 2 | `agent status <id>` | Fetches the latest task status payload through `command_status` |
236
+ | 3 | `agent result <id>` | Fetches the completed task result payload through `command_result` |
237
+
238
+ ### Notes
239
+
240
+ - `agent run` is asynchronous: it returns immediately after the backend accepts
241
+ the task and prints a follow-up `agent status` command with the generated task
242
+ ID.
243
+ - `agent status` prints the backend status payload as-is. In practice this is a
244
+ JSON object that commonly includes fields such as `id`, `status`,
245
+ `statusCode`, `processState`, `message`, `agentState`, `agentHistory`, and
246
+ `commandResult`.
247
+ - `agent result` prints the backend result payload as-is. Depending on the task,
248
+ it may be plain text or structured JSON.
249
+ - These commands are task-ID based and do not require an active CLI browser
250
+ session slot. The global `-s=<name>` option is therefore usually not relevant
251
+ for `agent-*` follow-up calls.
252
+ - `agent` subcommands are not supported inside `batch` mode.
253
+ - `agent run` performs a short post-submit status probe so obvious missing-LLM
254
+ configuration failures can be surfaced immediately instead of leaving you with
255
+ a task ID that will never succeed.
256
+
257
+ ### Use cases
258
+
259
+ #### 1. Submit an autonomous agent task
260
+
261
+ ```shell
262
+ browser4-cli agent run "Open example.com and summarize the hero section"
263
+ ```
264
+
265
+ Typical output:
266
+
267
+ ```text
268
+ Task submitted: agent-task-1
269
+ Use 'browser4-cli agent status agent-task-1' to check progress.
270
+ ```
271
+
272
+ #### 2. Poll task progress
273
+
274
+ ```shell
275
+ browser4-cli agent status agent-task-1
276
+ ```
277
+
278
+ Example status payload:
279
+
280
+ ```json
281
+ {"id":"agent-task-1","status":"RUNNING"}
282
+ ```
283
+
284
+ On a real Browser4 backend the payload can be richer and may include lifecycle
285
+ details such as `processState`, agent history snapshots, or an embedded partial
286
+ `commandResult`.
287
+
288
+ #### 3. Read the final result
289
+
290
+ ```shell
291
+ browser4-cli agent result agent-task-1
292
+ ```
293
+
294
+ If the backend returns a structured `CommandResult`, expect fields such as
295
+ `summary`, `pageSummary`, `fields`, `links`, or `xsqlResultSet`.
296
+
297
+ ## Swarm scrape workflow (`swarm <subcommand>`)
298
+
299
+ The `swarm` subcommands support a swarm scrape workflow where one CLI session
300
+ coordinates multiple browser contexts in the Browser4 backend.
301
+
302
+ Use the spaced `swarm <subcommand>` form:
303
+
304
+ ```shell
305
+ browser4-cli swarm create
306
+ browser4-cli swarm submit https://example.com
307
+ ```
308
+
309
+ ### Command lifecycle
310
+
311
+ | Step | Command | What it does |
312
+ |---|---|---|
313
+ | 1 | `swarm create` | Opens a swarm scrape session and persists the returned session ID in the current CLI slot |
314
+ | 2 | `swarm submit [url]` | Submits one direct URL plus any URLs from `--seed-file` as scrape jobs through `ScrapeController.submit(payload)` |
315
+ | 3 | `swarm status <id>` | Calls `ScrapeController.getStatus(id)` and prints the returned scrape job status JSON |
316
+ | 4 | `swarm result <id>` | Calls `ScrapeController.getResult(id)` and prints the returned scrape job result JSON |
317
+
318
+ ### Notes
319
+
320
+ - `swarm create` accepts backend capability hints such as `--profile-mode`,
321
+ `--max-open-tabs`, `--max-browser-contexts`, and `--display-mode`.
322
+ - `swarm submit` accepts either a direct positional URL, `--seed-file`, or both.
323
+ Seed files are plain text files with one URL per line; blank lines and lines
324
+ starting with `#` are ignored.
325
+ - `swarm submit` maps CLI flags like `--deadline`, `--expires`, `--refresh`,
326
+ `--parse`, and `--store-content` into the raw submission payload sent to the
327
+ scrape REST API.
328
+ - `swarm status` and `swarm result` are read-only follow-up commands; keep the job ID
329
+ printed by `swarm submit`.
330
+
331
+ ### Use cases
332
+
333
+ #### 1. Create a supervised swarm scrape session for manual monitoring
334
+
335
+ ```shell
336
+ browser4-cli swarm create \
337
+ --profile-mode=TEMPORARY \
338
+ --max-open-tabs=12 \
339
+ --max-browser-contexts=3 \
340
+ --display-mode=HEADLESS
341
+ ```
342
+
343
+ Use this when you want multiple isolated browser contexts and you still want to
344
+ watch the run visually.
345
+
346
+ #### 2. Submit a seed crawl as scrape jobs
347
+
348
+ ```shell
349
+ browser4-cli swarm submit https://example.com/direct \
350
+ --seed-file=./swarm-seeds.txt \
351
+ --deadline=2026-03-30T00:00:00Z \
352
+ --expires=1d \
353
+ --refresh \
354
+ --parse \
355
+ --store-content
356
+ ```
357
+
358
+ Example `swarm-seeds.txt`:
359
+
360
+ ```text
361
+ # campaign landing pages
362
+ https://example.com/seed-1
363
+ https://example.com/seed-2
364
+ ```
365
+
366
+ This pattern is useful for warming caches, refreshing a URL list, or launching
367
+ parallel collection across a curated seed set.
368
+
369
+ #### 3. Poll and fetch the result
370
+
371
+ ```shell
372
+ browser4-cli swarm status scrape-task-4
373
+ browser4-cli swarm result scrape-task-4
374
+ ```
375
+
376
+ The status and result commands print the scrape job response payload as-is. In
377
+ the current backend, `getResult(id)` returns the same response envelope type as
378
+ `getStatus(id)`.
179
379
 
180
380
  ## Element References
181
381
 
@@ -218,16 +418,16 @@ gate for commands that require an active Browser4 session.
218
418
  | `open -s=<name>` | Reads/writes the named session state file | Opens, reuses, or refreshes the named session for that slot; subsequent `-s=<name>` commands use the same slot |
219
419
  | Command succeeds through `with_session()` | `sessionId` stays unchanged | The command uses the persisted session normally |
220
420
  | Command fails because the server reports a stale / expired session and `recover_stale = false` | `invalidate_session()` clears `sessionId`, `activeSelector`, and `lastMousePosition`, while keeping `baseUrl` | The command fails with `Saved session expired. Run "browser4-cli open" first.` |
221
- | `goto` is invoked but the saved session is missing or no longer `active` in the backend | `invalidate_session()` clears the saved `sessionId`, `activeSelector`, and `lastMousePosition` | The command fails with `No active session for "goto". Run "browser4-cli open" to create or refresh the session first.` |
421
+ | `goto` is invoked but the saved session is missing or no longer `active` in the backend | `invalidate_session()` clears any stale saved `sessionId`, then `create_session()` writes a fresh session before navigation continues | `goto` automatically refreshes the session and proceeds to the requested URL |
222
422
  | `close` with an active session | `clear_state()` removes only the current session state file after best-effort remote close | The selected default or named session is fully cleared |
223
423
  | `close` with no persisted `sessionId` | `clear_state()` best-effort removes the current session slot | Prints `No active session. Run "browser4-cli open" first.` and exits successfully as a no-op |
224
424
  | `close-all` / `kill-all` | `clear_all_state()` removes the default state file and all named session files | All persisted CLI session files are cleared |
225
425
 
226
426
  Notes:
227
427
 
228
- - `goto` reuses only the current backend-`active` session. It does not create a
229
- new session automatically; run `browser4-cli open` first if the saved session
230
- is missing or stale.
428
+ - `goto` first tries to reuse the current backend-`active` session. If the saved
429
+ session is missing, stale, or the backend had been stopped, it automatically
430
+ opens a fresh session for the current slot before navigating.
231
431
  - `open` first checks whether the saved session for the current slot is still
232
432
  backend-`active`. It reuses active sessions and refreshes stale ones by
233
433
  creating a new session for the same slot.
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser4-cli",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Browser automation CLI for AI agents",
5
5
  "type": "module",
6
6
  "files": [
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "scripts": {
17
17
  "version:sync": "node scripts/sync-version.js",
18
- "version": "npm run version:sync && git add browser4-cli/Cargo.toml",
18
+ "version": "npm run version:sync && git add browser4-cli/Cargo.toml browser4-cli/Cargo.lock",
19
19
  "build:native": "npm run version:sync && cargo build --release --manifest-path browser4-cli/Cargo.toml && node scripts/copy-native.js",
20
20
  "build:linux": "npm run version:sync && docker compose -f docker/docker-compose.yml run --rm build-linux",
21
21
  "build:macos": "npm run version:sync && (cargo build --release --manifest-path browser4-cli/Cargo.toml --target aarch64-apple-darwin & cargo build --release --manifest-path browser4-cli/Cargo.toml --target x86_64-apple-darwin & wait) && cp cli/target/aarch64-apple-darwin/release/browser4 bin/browser4-darwin-arm64 && cp cli/target/x86_64-apple-darwin/release/browser4 bin/browser4-darwin-x64",
@@ -5,10 +5,10 @@
5
5
  * Run this script before building or releasing.
6
6
  */
7
7
 
8
- import { execSync } from "child_process";
9
- import { readFileSync, writeFileSync } from "fs";
10
- import { dirname, join } from "path";
11
- import { fileURLToPath } from "url";
8
+ import {execSync} from "child_process";
9
+ import {readFileSync, writeFileSync} from "fs";
10
+ import {dirname, join} from "path";
11
+ import {fileURLToPath} from "url";
12
12
 
13
13
  const __dirname = dirname(fileURLToPath(import.meta.url));
14
14
  const rootDir = join(__dirname, "..");
@@ -47,7 +47,7 @@ if (cargoVersionRegex.test(cargoToml)) {
47
47
  // Update Cargo.lock to match Cargo.toml
48
48
  if (cargoTomlUpdated) {
49
49
  try {
50
- execSync("cargo update -p browser4 --offline", {
50
+ execSync("cargo update -p browser4-cli --offline", {
51
51
  cwd: cliDir,
52
52
  stdio: "pipe",
53
53
  });
@@ -55,7 +55,7 @@ if (cargoTomlUpdated) {
55
55
  } catch {
56
56
  // --offline may fail if package not in cache, try without it
57
57
  try {
58
- execSync("cargo update -p browser4", {
58
+ execSync("cargo update -p browser4-cli", {
59
59
  cwd: cliDir,
60
60
  stdio: "pipe",
61
61
  });