@generativereality/browser-automation 0.4.9 → 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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +6 -0
- package/dist/index.js +142 -5
- package/package.json +3 -2
- package/skills/browser/SKILL.md +6 -0
|
@@ -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.
|
|
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
|
@@ -9,7 +9,7 @@ import { execFileSync, spawnSync } from "node:child_process";
|
|
|
9
9
|
import { fileURLToPath } from "node:url";
|
|
10
10
|
//#region package.json
|
|
11
11
|
var name = "@generativereality/browser-automation";
|
|
12
|
-
var version = "0.4.
|
|
12
|
+
var version = "0.4.10";
|
|
13
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
14
|
var package_default = {
|
|
15
15
|
name,
|
|
@@ -27,7 +27,8 @@ var package_default = {
|
|
|
27
27
|
"dev": "bun run ./src/index.ts",
|
|
28
28
|
"build": "tsdown",
|
|
29
29
|
"typecheck": "tsc --noEmit",
|
|
30
|
-
"check": "npm run typecheck && bash scripts/check-one-port.sh && npm run build",
|
|
30
|
+
"check": "npm run typecheck && bash scripts/check-one-port.sh && npm run build && npm test",
|
|
31
|
+
"test": "node --test \"test/**/*.test.mjs\"",
|
|
31
32
|
"release": "bumpp && npm publish",
|
|
32
33
|
"sync-plugin": "bash scripts/sync-plugin.sh",
|
|
33
34
|
"prepack": "npm run build"
|
|
@@ -66,6 +67,117 @@ var package_default = {
|
|
|
66
67
|
}
|
|
67
68
|
};
|
|
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
|
+
}
|
|
180
|
+
//#endregion
|
|
69
181
|
//#region src/core/session.ts
|
|
70
182
|
const DIR = join(homedir(), ".browser-automation", "sessions");
|
|
71
183
|
function file(name) {
|
|
@@ -2268,13 +2380,38 @@ const subCommands = new Map([
|
|
|
2268
2380
|
["prune", gcCommand],
|
|
2269
2381
|
["port", portCommand]
|
|
2270
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
|
+
}
|
|
2271
2394
|
async function run() {
|
|
2272
|
-
|
|
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, {
|
|
2273
2406
|
name: "browser-automation",
|
|
2274
2407
|
version,
|
|
2275
2408
|
description,
|
|
2276
|
-
subCommands,
|
|
2277
|
-
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
|
+
}
|
|
2278
2415
|
});
|
|
2279
2416
|
}
|
|
2280
2417
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@generativereality/browser-automation",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.10",
|
|
4
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": {
|
|
@@ -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"
|
package/skills/browser/SKILL.md
CHANGED
|
@@ -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
|