browser4-cli 0.1.27 → 0.1.29

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
@@ -169,8 +169,8 @@ browser4-cli -s mysession goto https://example.com
169
169
 
170
170
  | Command | Description |
171
171
  |---|---|
172
- | `click <ref> [button]` | Click an element. `--modifiers` for modifier keys. |
173
- | `dblclick <ref> [button]` | Double-click an element. `--modifiers` for modifier keys. |
172
+ | `click <ref> [button]` | Click an element. `--modifiers` for modifier keys, `--follow` to detect and switch to new tabs opened by the click. |
173
+ | `dblclick <ref> [button]` | Double-click an element. `--modifiers` for modifier keys, `--follow` to detect and switch to new tabs. |
174
174
  | `hover <ref>` | Hover over an element. |
175
175
  | `drag <startRef> <endRef>` | Drag and drop between two elements. |
176
176
  | `fill <ref> <text>` | Fill text into an editable element. `--submit` to press Enter after. `--verify` to confirm. |
@@ -193,7 +193,7 @@ browser4-cli select e12 "option-value"
193
193
 
194
194
  | Command | Description |
195
195
  |---|---|
196
- | `press <key> [ref]` | Press a key (`a`, `Enter`, `ArrowLeft`, `Escape`). Supports `--verify`. |
196
+ | `press <key> [ref]` | Press a key (`a`, `Enter`, `ArrowLeft`, `Escape`). Supports `--verify`, `--follow` (detect new tabs). |
197
197
  | `keydown <key>` | Press and hold a key. |
198
198
  | `keyup <key>` | Release a key. |
199
199
  | `mousemove <x> <y>` | Move mouse to coordinates. |
@@ -264,11 +264,11 @@ browser4-cli tab-close 1
264
264
  |---|---|
265
265
  | `snapshot` | Capture an accessibility snapshot. See [Snapshot](#snapshot) below. |
266
266
  | `get <mode> <selector> [name]` | Extract data from a page element in one of six modes (see below). |
267
- | `eval <expression> [ref]` | Evaluate JavaScript on the page or a target element. `--file <path>` to read from file. `--json` to wrap scalar results. |
267
+ | `eval <expression> [ref]` | Evaluate JavaScript on the page or a target element. `--file <path>`, `--base64`, or `--stdin` to provide the expression. `--json` to wrap scalar results. |
268
268
  | `generate-locator <ref>` | Generate a stable CSS selector path for an element. |
269
269
  | `htmlsnapshot` | Short form of `htmlsnapshot capture`. Capture a static HTML snapshot. See [HTML Snapshot](#dom-snapshot) below. |
270
270
  | `htmlsnapshot capture` | Capture a static HTML snapshot. See [HTML Snapshot](#dom-snapshot) below. |
271
- | `extract <instruction>` | Extract structured data with AI. `--schema <file>` for typed output. `--filename <path>`, `--raw`. |
271
+ | `extract <instruction>` | Extract structured data with AI. `--schema <json>` for typed output. `--filename <path>`, `--raw`. |
272
272
  | `summarize [instruction]` | Summarize page content with AI. `--selector <css>`, `--filename <path>`, `--raw`. |
273
273
 
274
274
  `get` modes:
@@ -286,8 +286,10 @@ browser4-cli tab-close 1
286
286
  browser4-cli eval "document.title"
287
287
  browser4-cli eval "el => el.textContent" e15
288
288
  browser4-cli eval --file script.js
289
+ browser4-cli eval --base64 ZG9jdW1lbnQudGl0bGU=
289
290
  browser4-cli generate-locator e5
290
291
  browser4-cli extract "product name, price, and rating"
292
+ browser4-cli extract "contacts" --schema '{"type":"object","properties":{"name":{"type":"string"},"email":{"type":"string"}}}'
291
293
  browser4-cli summarize --selector "#reviews"
292
294
  ```
293
295
 
@@ -511,7 +513,7 @@ paginated at 2000 lines by default; `get all text` is not paginated by default.
511
513
  > **correlated multi-field extraction** (title + price + URL per item), use
512
514
  > `htmlsnapshot query` with X-SQL's `DOM_LOAD_AND_SELECT` — it scopes each row
513
515
  > to a parent container so fields stay aligned. See the
514
- > [list-page scraping pattern](skill/references/x-sql-dom-load-select.md).
516
+ > [list-page scraping pattern](skills/browser4-cli/references/x-sql-dom-load-select.md).
515
517
 
516
518
  ```bash
517
519
  browser4-cli htmlsnapshot get all text "h2 a"
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.27",
3
+ "version": "0.1.29",
4
4
  "description": "Browser automation CLI for AI agents",
5
5
  "type": "module",
6
6
  "files": [
package/scripts/README.md CHANGED
@@ -0,0 +1,135 @@
1
+ # CLI Scripts
2
+
3
+ Build, install, test, and publish utilities for the browser4-cli native binary and npm package.
4
+
5
+ ## Build
6
+
7
+ | Script | Platform | Purpose |
8
+ |--------|----------|---------|
9
+ | `build-all-platforms.sh` | Linux/macOS | Docker-based cross-compilation for all targets |
10
+ | `build-all-platforms.ps1` | Windows | PowerShell equivalent — same targets via Docker |
11
+ | `copy-native.js` | All (Node) | Copies the compiled Rust binary to `bin/` with platform-specific naming |
12
+
13
+ Both build-all-platforms scripts produce binaries for:
14
+ - `x86_64-unknown-linux-gnu` (Linux x64, glibc)
15
+ - `aarch64-unknown-linux-gnu` (Linux arm64, glibc)
16
+ - `x86_64-unknown-linux-musl` (Linux x64, musl)
17
+ - `aarch64-unknown-linux-musl` (Linux arm64, musl)
18
+ - `x86_64-pc-windows-gnu` (Windows x64)
19
+ - `x86_64-apple-darwin` (macOS x64)
20
+ - `aarch64-apple-darwin` (macOS arm64)
21
+
22
+ Options: `--skip-docker-build`, `--dry-run`.
23
+
24
+ `copy-native.js` expects a pre-built binary at `browser4-cli/target/release/browser4-cli` and copies it to `bin/browser4-cli-<platform>-<arch>`.
25
+
26
+ ## Install
27
+
28
+ | Script | Platform | Purpose |
29
+ |--------|----------|---------|
30
+ | `install-browser4-cli.sh` | Linux/macOS | Download and install the native binary |
31
+ | `install-browser4-cli.ps1` | Windows | PowerShell equivalent |
32
+
33
+ Both scripts auto-detect OS, CPU architecture, and libc variant (glibc vs musl on Linux). They download the matching binary from GitHub Releases or Alibaba Cloud OSS (auto-selected by locale: OSS first in China mainland). The binary is installed to a user-local directory and optionally added to PATH.
34
+
35
+ ### Common options
36
+
37
+ | Option | Description |
38
+ |--------|-------------|
39
+ | `--version, -v TAG` | Release tag (e.g. `v4.11.0`). Default: latest. |
40
+ | `--install-dir, -d DIR` | Install directory (default: `~/.local/bin` on Unix, `%LOCALAPPDATA%\Programs\browser4-cli` on Windows). |
41
+ | `--source SRC` | Force download source: `github` or `oss`. Default: auto (locale-aware). |
42
+ | `--no-path` / `-AddToPath:$false` | Skip adding the install directory to PATH. |
43
+ | `--silent, -s` / `-Silent` | Suppress non-error output. |
44
+ | `--dry-run` / `-DryRun` | Print what would be done without doing it. |
45
+ | `--skip-if-installed` / `-SkipIfInstalled` | Skip download if binary already exists. |
46
+ | `--skip-local` / `-SkipLocal` | Skip local bundled binary check; always download. |
47
+ | `--locate` (sh only) | Print detection results and exit (no install). |
48
+
49
+ ### One-liner install
50
+
51
+ ```shell
52
+ # Linux / macOS
53
+ curl -fsSL https://raw.githubusercontent.com/platonai/Browser4/main/cli/scripts/install-browser4-cli.sh | bash
54
+
55
+ # Windows (PowerShell)
56
+ iwr -useb https://raw.githubusercontent.com/platonai/Browser4/main/cli/scripts/install-browser4-cli.ps1 | iex
57
+ ```
58
+
59
+ ## Test
60
+
61
+ | Script | Platform | Purpose |
62
+ |--------|----------|---------|
63
+ | `smoke-test-runtime-bundle.sh` | Linux/macOS | End-to-end CLI smoke test against a runtime bundle |
64
+
65
+ Runs a full CLI smoke test suitable for CI and local development:
66
+
67
+ 1. Extracts a platform runtime bundle (`.tar.gz` or `.zip`)
68
+ 2. Sets up a local runtime directory (no network download)
69
+ 3. Starts a Python HTTP server serving a minimal interactive page
70
+ 4. Executes the full command cycle: `open` → `goto` → `snapshot` → `type` → `click` → `get` → `eval` → `screenshot` → `wait` → `close` → `kill-all`
71
+ 5. Reports pass/fail for each step
72
+
73
+ ```shell
74
+ ./smoke-test-runtime-bundle.sh <cli-binary> <bundle-archive> [test-port] [timeout-secs]
75
+ ```
76
+
77
+ ### Install script tests
78
+
79
+ | File | Purpose |
80
+ |------|---------|
81
+ | `tests/install-browser4-cli.tests.sh` | Unit tests for the Unix install script |
82
+ | `tests/install-browser4-cli.tests.ps1` | Unit tests for the Windows install script (Pester) |
83
+
84
+ ## Publish (npm)
85
+
86
+ | Script | Purpose |
87
+ |--------|---------|
88
+ | `npm-publish-check.js` | Shared library: reads package metadata and compares local vs npm registry version |
89
+ | `check-npm-publish-needed.js` | CLI wrapper: checks whether a publish is needed and prints the decision |
90
+ | `publish-if-needed.js` | Publishes to npm only when the local version differs from the registry |
91
+ | `postinstall.js` | npm `postinstall` hook: downloads the platform native binary after `npm install` |
92
+
93
+ ### Version check
94
+
95
+ ```shell
96
+ node scripts/check-npm-publish-needed.js # human-readable output
97
+ node scripts/check-npm-publish-needed.js --json # JSON output
98
+ node scripts/check-npm-publish-needed.js --shell # shell-var output
99
+ node scripts/check-npm-publish-needed.js --github-output # append to $GITHUB_OUTPUT
100
+ ```
101
+
102
+ ### Conditional publish
103
+
104
+ ```shell
105
+ node scripts/publish-if-needed.js # publish if versions differ
106
+ node scripts/publish-if-needed.js --dry-run # print what would happen
107
+ ```
108
+
109
+ Optional env: `BROWSER4_CLI_NPM_REMOTE_VERSION` to override the remote version for testing.
110
+
111
+ ### Postinstall
112
+
113
+ `postinstall.js` runs automatically after `npm install browser4-cli`. It detects the platform and downloads the matching native binary to `bin/`. On global installs, it also patches npm's bin shims to invoke the native binary directly.
114
+
115
+ ## Documentation
116
+
117
+ | Script | Platform | Purpose |
118
+ |--------|----------|---------|
119
+ | `enumerate-help.ps1` | Windows (pwsh) | Discovers all CLI commands/subcommands and generates categorized help output |
120
+
121
+ Enumerates every browser4-cli command (including hidden ones), captures `--help` output for each, and saves organized documentation to `cli/help-output/`:
122
+
123
+ - Top-level help overview
124
+ - One file per command (with numbered prefixes for ordering)
125
+ - Prefix group overviews (`swarm`, `agent`, `htmlsnapshot`, `crawl`, `snapshot`)
126
+ - `INDEX.md` for easy navigation
127
+
128
+ ```powershell
129
+ .\enumerate-help.ps1
130
+ .\enumerate-help.ps1 -Binary "C:\tools\browser4-cli.exe" -OutDir ".\docs\cli-help"
131
+ ```
132
+
133
+ ---
134
+
135
+ This README is intentionally concise; extend as the script collection grows.
@@ -9,7 +9,7 @@
9
9
  # 1. Extracts the platform runtime bundle (.tar.gz or .zip)
10
10
  # 2. Sets up a local "installed" runtime directory (no network download)
11
11
  # 3. Starts a Python HTTP server serving a minimal interactive page
12
- # 4. Runs CLI commands: open → goto → type → click → close → kill-all
12
+ # 4. Runs CLI commands: open → goto → snapshot → type → click → get → eval → screenshot → wait → close → kill-all
13
13
  # 5. Reports pass/fail for each step
14
14
  #
15
15
  # Designed for CI (GitHub Actions) but also runs on developer machines.
@@ -101,11 +101,16 @@ case "$BUNDLE_ARCHIVE" in
101
101
  tar xzf "$BUNDLE_ARCHIVE" -C "$EXTRACT_DIR"
102
102
  ;;
103
103
  *.zip)
104
+ # On Windows (Git Bash / MSYS2), Python is a native Windows program.
105
+ # MSYS2 auto-converts command-line *arguments* that look like Unix
106
+ # paths, but it cannot see paths embedded inside a -c string literal.
107
+ # Pass the paths as sys.argv entries so they are correctly translated
108
+ # to Windows-native paths before Python receives them.
104
109
  python3 -c "
105
110
  import zipfile, sys
106
- with zipfile.ZipFile('$BUNDLE_ARCHIVE', 'r') as z:
107
- z.extractall('$EXTRACT_DIR')
108
- " 2>/dev/null || unzip -q "$BUNDLE_ARCHIVE" -d "$EXTRACT_DIR"
111
+ with zipfile.ZipFile(sys.argv[1], 'r') as z:
112
+ z.extractall(sys.argv[2])
113
+ " "$BUNDLE_ARCHIVE" "$EXTRACT_DIR" 2>/dev/null || unzip -q "$BUNDLE_ARCHIVE" -d "$EXTRACT_DIR"
109
114
  ;;
110
115
  *)
111
116
  fail "Unsupported archive format: $BUNDLE_ARCHIVE (expected .tar.gz or .zip)"
@@ -153,6 +158,7 @@ cat > "$TEST_PAGE" <<'HTML'
153
158
  <h1>Browser4 Smoke Test</h1>
154
159
  <input id="input1" type="text" value="">
155
160
  <button id="btn1" onclick="document.getElementById('input1').value='clicked'">Click Me</button>
161
+ <span id="output">ready</span>
156
162
  </body></html>
157
163
  HTML
158
164
 
@@ -235,10 +241,25 @@ check_step "type" type "hello-smoke" "#input1"
235
241
  # 4d. click — click the button
236
242
  check_step "click" click "#btn1"
237
243
 
238
- # 4e. closeclose the active session
244
+ # 4e. snapshotcapture page accessibility tree
245
+ check_step "snapshot" snapshot
246
+
247
+ # 4f. get text — extract text content from an element
248
+ check_step "get text" get text "#output"
249
+
250
+ # 4g. eval — execute JavaScript on the page
251
+ check_step "eval" eval "document.title"
252
+
253
+ # 4h. screenshot — capture page screenshot
254
+ check_step "screenshot" screenshot
255
+
256
+ # 4i. wait — wait for an element to be present
257
+ check_step "wait" wait "#output"
258
+
259
+ # 4j. close — close the active session
239
260
  check_step "close" close
240
261
 
241
- # 4f. kill-all — stop the server and clean up
262
+ # 4k. kill-all — stop the server and clean up
242
263
  check_step "kill-all" kill-all
243
264
 
244
265
  # ---------------------------------------------------------------------------