@generativereality/browser-automation 0.4.8 → 0.4.10

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "browser-automation",
3
3
  "description": "Daemonless, per-tab-isolated browser automation for Claude Code via the `browser-automation` CLI. Drives one shared headed Chrome (persistent profile + extensions) over per-target CDP — many parallel sessions, no focus stealing, nothing long-lived to crash.",
4
- "version": "0.4.8",
4
+ "version": "0.4.10",
5
5
  "author": {
6
6
  "name": "generativereality"
7
7
  },
package/README.md CHANGED
@@ -122,6 +122,12 @@ same one-action-per-snapshot rule as Playwright refs.
122
122
 
123
123
  ## Notes & limits
124
124
 
125
+ - **Values are plain POSIX argv.** A positional such as `fill`'s value may contain
126
+ anything — `--force`, a markdown `---` rule, newlines — as long as the shell
127
+ hands it over as one element (quote it). Only an element that *begins* with a
128
+ dash and looks like an option (`--force`, `-5`) is read as one; to pass such a
129
+ value literally, end option parsing with `--`: `fill -t <id> -- e3 "--force"`.
130
+ An unknown option is an error that names the offending element.
125
131
  - Interactions are **JS-dispatched** (`element.click()`, native value setter +
126
132
  `input`/`change`), which works on background tabs (native CDP mouse events do
127
133
  not reliably reach a non-foreground tab in headed Chrome). Synthetic events are
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import updateNotifier from "update-notifier";
2
3
  import { cli, define } from "gunshi";
3
4
  import { consola } from "consola";
4
5
  import { homedir } from "node:os";
@@ -7,8 +8,175 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, s
7
8
  import { execFileSync, spawnSync } from "node:child_process";
8
9
  import { fileURLToPath } from "node:url";
9
10
  //#region package.json
10
- var version = "0.4.8";
11
+ var name = "@generativereality/browser-automation";
12
+ var version = "0.4.10";
11
13
  var description = "Daemonless, per-tab-isolated browser automation CLI for Claude Code. Drives one shared headed Chrome (persistent profile + extensions) over per-target CDP — many parallel sessions, no focus stealing, nothing long-lived to crash.";
14
+ var package_default = {
15
+ name,
16
+ version,
17
+ description,
18
+ type: "module",
19
+ bin: { "browser-automation": "dist/index.js" },
20
+ files: [
21
+ "dist",
22
+ ".claude-plugin",
23
+ "skills",
24
+ "scripts"
25
+ ],
26
+ scripts: {
27
+ "dev": "bun run ./src/index.ts",
28
+ "build": "tsdown",
29
+ "typecheck": "tsc --noEmit",
30
+ "check": "npm run typecheck && bash scripts/check-one-port.sh && npm run build && npm test",
31
+ "test": "node --test \"test/**/*.test.mjs\"",
32
+ "release": "bumpp && npm publish",
33
+ "sync-plugin": "bash scripts/sync-plugin.sh",
34
+ "prepack": "npm run build"
35
+ },
36
+ keywords: [
37
+ "claude-code",
38
+ "browser-automation",
39
+ "cdp",
40
+ "chrome-devtools-protocol",
41
+ "playwright-alternative",
42
+ "ai-agents"
43
+ ],
44
+ author: "motin",
45
+ license: "MIT",
46
+ repository: {
47
+ "type": "git",
48
+ "url": "git+https://github.com/generativereality/browser-automation.git"
49
+ },
50
+ homepage: "https://github.com/generativereality/browser-automation",
51
+ engines: { "node": ">=22.0.0" },
52
+ publishConfig: {
53
+ "registry": "https://registry.npmjs.org",
54
+ "access": "public"
55
+ },
56
+ dependencies: {
57
+ "consola": "^3.4.0",
58
+ "gunshi": "^0.23.0",
59
+ "update-notifier": "^7.3.1"
60
+ },
61
+ devDependencies: {
62
+ "@types/node": "^22.0.0",
63
+ "@types/update-notifier": "^6.0.8",
64
+ "bumpp": "^9.11.1",
65
+ "tsdown": "^0.12.0",
66
+ "typescript": "^5.8.0"
67
+ }
68
+ };
69
+ //#endregion
70
+ //#region src/core/argv.ts
71
+ var UsageError = class extends Error {
72
+ constructor(message) {
73
+ super(message);
74
+ this.name = "UsageError";
75
+ }
76
+ };
77
+ const COMMON = {
78
+ help: {
79
+ type: "boolean",
80
+ short: "h"
81
+ },
82
+ version: {
83
+ type: "boolean",
84
+ short: "v"
85
+ }
86
+ };
87
+ const PLACEHOLDER_PREFIX = "\0positional:";
88
+ function placeholder(i) {
89
+ return `${PLACEHOLDER_PREFIX}${i}`;
90
+ }
91
+ /** Map gunshi's positionals (which contain placeholders) back to the real values. */
92
+ function restorePositionals(positionals, real) {
93
+ return positionals.map((p) => {
94
+ if (!p.startsWith(PLACEHOLDER_PREFIX)) return p;
95
+ return real[Number(p.slice(12))] ?? p;
96
+ });
97
+ }
98
+ function isOptionShaped(arg) {
99
+ return /^--?[A-Za-z0-9]/.test(arg);
100
+ }
101
+ function separatorHint(sub, positionals, token) {
102
+ return `To pass it as a value, put '--' before the positionals: browser-automation ${sub} [options] -- ${[...positionals, token].map((p) => `'${p}'`).join(" ")}`;
103
+ }
104
+ /**
105
+ * Canonicalise everything after the subcommand.
106
+ *
107
+ * @param sub the subcommand name (argv[0])
108
+ * @param rest argv after the subcommand
109
+ * @param schema the command's declared args (gunshi's `args` table)
110
+ */
111
+ function canonicalize(sub, rest, schema) {
112
+ const specs = {
113
+ ...COMMON,
114
+ ...schema
115
+ };
116
+ const byShort = /* @__PURE__ */ new Map();
117
+ for (const [name, spec] of Object.entries(specs)) if (spec.short) byShort.set(spec.short, name);
118
+ const options = [];
119
+ const positionals = [];
120
+ const unknown = (token) => {
121
+ throw new UsageError(`'${token}' is not an option of '${sub}'. ${separatorHint(sub, positionals, token)}`);
122
+ };
123
+ const takesValue = (name) => specs[name].type !== "boolean";
124
+ let i = 0;
125
+ let terminated = false;
126
+ while (i < rest.length) {
127
+ const arg = rest[i++];
128
+ if (!terminated && arg === "--") {
129
+ terminated = true;
130
+ continue;
131
+ }
132
+ if (terminated || !isOptionShaped(arg)) {
133
+ positionals.push(arg);
134
+ continue;
135
+ }
136
+ if (arg.startsWith("--")) {
137
+ const eq = arg.indexOf("=");
138
+ const name = eq === -1 ? arg.slice(2) : arg.slice(2, eq);
139
+ if (!(name in specs) || specs[name].type === "positional") return unknown(arg);
140
+ if (!takesValue(name)) {
141
+ if (eq !== -1) throw new UsageError(`'--${name}' is a flag and takes no value (got '${arg}')`);
142
+ options.push(`--${name}`);
143
+ continue;
144
+ }
145
+ let value;
146
+ if (eq !== -1) value = arg.slice(eq + 1);
147
+ else if (i < rest.length) value = rest[i++];
148
+ else throw new UsageError(`'${arg}' needs a value`);
149
+ options.push(`--${name}=${value}`);
150
+ continue;
151
+ }
152
+ let j = 1;
153
+ while (j < arg.length) {
154
+ const short = arg[j++];
155
+ const name = byShort.get(short);
156
+ if (!name) return unknown(`-${short}`);
157
+ if (!takesValue(name)) {
158
+ options.push(`--${name}`);
159
+ continue;
160
+ }
161
+ let remainder = arg.slice(j);
162
+ if (remainder.startsWith("=")) remainder = remainder.slice(1);
163
+ let value;
164
+ if (remainder.length > 0) value = remainder;
165
+ else if (i < rest.length) value = rest[i++];
166
+ else throw new UsageError(`'-${short}' needs a value`);
167
+ options.push(`--${name}=${value}`);
168
+ break;
169
+ }
170
+ }
171
+ return {
172
+ argv: [
173
+ sub,
174
+ ...options,
175
+ ...positionals.map((_, k) => placeholder(k))
176
+ ],
177
+ positionals
178
+ };
179
+ }
12
180
  //#endregion
13
181
  //#region src/core/session.ts
14
182
  const DIR = join(homedir(), ".browser-automation", "sessions");
@@ -2212,13 +2380,38 @@ const subCommands = new Map([
2212
2380
  ["prune", gcCommand],
2213
2381
  ["port", portCommand]
2214
2382
  ]);
2383
+ function withRealPositionals(cmd, real) {
2384
+ return {
2385
+ ...cmd,
2386
+ async run(ctx) {
2387
+ return cmd.run?.({
2388
+ ...ctx,
2389
+ positionals: restorePositionals(ctx.positionals, real)
2390
+ });
2391
+ }
2392
+ };
2393
+ }
2215
2394
  async function run() {
2216
- await cli(process.argv.slice(2), defaultCommand, {
2395
+ let argv = process.argv.slice(2);
2396
+ let commands = subCommands;
2397
+ const sub = argv[0];
2398
+ const command = sub === void 0 ? void 0 : subCommands.get(sub);
2399
+ if (sub !== void 0 && command) {
2400
+ const canonical = canonicalize(sub, argv.slice(1), command.args ?? {});
2401
+ argv = canonical.argv;
2402
+ commands = new Map(subCommands);
2403
+ commands.set(sub, withRealPositionals(command, canonical.positionals));
2404
+ }
2405
+ await cli(argv, defaultCommand, {
2217
2406
  name: "browser-automation",
2218
2407
  version,
2219
2408
  description,
2220
- subCommands,
2221
- renderHeader: null
2409
+ subCommands: commands,
2410
+ renderHeader: null,
2411
+ renderValidationErrors: async (_ctx, error) => {
2412
+ process.exitCode = 1;
2413
+ return error.errors.map((e) => e instanceof Error ? e.message : String(e)).join("\n");
2414
+ }
2222
2415
  });
2223
2416
  }
2224
2417
  //#endregion
@@ -2227,6 +2420,12 @@ process.stdout.on("error", (err) => {
2227
2420
  if (err.code === "EPIPE") process.exit(0);
2228
2421
  throw err;
2229
2422
  });
2423
+ const notifier = updateNotifier({ pkg: package_default });
2424
+ notifier.notify();
2425
+ if (notifier.update && notifier.update.latest !== notifier.update.current) {
2426
+ const { current, latest } = notifier.update;
2427
+ process.stdout.write(`[browser-automation] OUTDATED ${current} < ${latest} — run: npm install -g ${name}@latest\n`);
2428
+ }
2230
2429
  run().catch((err) => {
2231
2430
  console.error(err instanceof Error ? err.message : String(err));
2232
2431
  process.exit(1);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@generativereality/browser-automation",
3
- "version": "0.4.8",
4
- "description": "Daemonless, per-tab-isolated browser automation CLI for Claude Code. Drives one shared headed Chrome (persistent profile + extensions) over per-target CDP \u2014 many parallel sessions, no focus stealing, nothing long-lived to crash.",
3
+ "version": "0.4.10",
4
+ "description": "Daemonless, per-tab-isolated browser automation CLI for Claude Code. Drives one shared headed Chrome (persistent profile + extensions) over per-target CDP — many parallel sessions, no focus stealing, nothing long-lived to crash.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "browser-automation": "dist/index.js"
@@ -16,7 +16,8 @@
16
16
  "dev": "bun run ./src/index.ts",
17
17
  "build": "tsdown",
18
18
  "typecheck": "tsc --noEmit",
19
- "check": "npm run typecheck && bash scripts/check-one-port.sh && npm run build",
19
+ "check": "npm run typecheck && bash scripts/check-one-port.sh && npm run build && npm test",
20
+ "test": "node --test \"test/**/*.test.mjs\"",
20
21
  "release": "bumpp && npm publish",
21
22
  "sync-plugin": "bash scripts/sync-plugin.sh",
22
23
  "prepack": "npm run build"
@@ -45,10 +46,12 @@
45
46
  },
46
47
  "dependencies": {
47
48
  "consola": "^3.4.0",
48
- "gunshi": "^0.23.0"
49
+ "gunshi": "^0.23.0",
50
+ "update-notifier": "^7.3.1"
49
51
  },
50
52
  "devDependencies": {
51
53
  "@types/node": "^22.0.0",
54
+ "@types/update-notifier": "^6.0.8",
52
55
  "bumpp": "^9.11.1",
53
56
  "tsdown": "^0.12.0",
54
57
  "typescript": "^5.8.0"
@@ -134,6 +134,12 @@ There's no `state-save`/`state-load` to manage — the profile *is* the auth sto
134
134
 
135
135
  ## Gotchas
136
136
 
137
+ - **Values may contain `--` freely.** `fill -s work e3 "see the --native flag"`
138
+ and a whole markdown brief with `---` rules go through as one quoted argv
139
+ element. Only a value that *begins* with a dash and is option-shaped
140
+ (`--force`, `-5`) needs the POSIX separator: `fill -s work -- e3 "--force"`.
141
+ An error naming the element (`'--force' is not an option of 'fill'`)
142
+ means exactly that — add `--`, do not re-quote.
137
143
  - **Refs go stale after any DOM change**, not just navigation. Snapshot → use
138
144
  those refs for one action → re-snapshot. "ref not found" means re-snapshot.
139
145
  - **`isTrusted` / synthetic events.** Clicks and fills are JS-dispatched by