@generativereality/browser-automation 0.4.17 → 0.4.19
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 +3 -1
- package/dist/index.js +312 -42
- package/package.json +1 -1
- package/scripts/launch-chrome.sh +36 -15
- package/skills/browser/SKILL.md +16 -3
|
@@ -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.19",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "generativereality"
|
|
7
7
|
},
|
package/README.md
CHANGED
|
@@ -170,7 +170,8 @@ same one-action-per-snapshot rule as Playwright refs.
|
|
|
170
170
|
button inside the zone works even when the zone div itself isn't
|
|
171
171
|
snapshot-interactive. After dropping, confirm with `read`/`screenshot` and pull
|
|
172
172
|
the result (often a `download --url` endpoint).
|
|
173
|
-
- `launch`
|
|
173
|
+
- `launch` works on macOS, Linux and Windows (on Windows it needs only Node; set
|
|
174
|
+
`BROWSER_AUTOMATION_CHROME` if `chrome.exe` is somewhere unusual). Anywhere else, start Chrome with
|
|
174
175
|
`--remote-debugging-port=<your port> --user-data-dir="<profile>"` — `browser-automation doctor` prints the port.
|
|
175
176
|
|
|
176
177
|
## Environment
|
|
@@ -185,6 +186,7 @@ same one-action-per-snapshot rule as Playwright refs.
|
|
|
185
186
|
repeats a rule is a copy of it, and goes stale the same way code does.
|
|
186
187
|
`doctor` prints it too, and warns if another user holds it.
|
|
187
188
|
- `BROWSER_AUTOMATION_CDP` — full CDP host, overriding the port entirely.
|
|
189
|
+
- `CHROME` / `BROWSER_AUTOMATION_CHROME` — the Chrome executable `launch` starts, when it is not in a standard place. Otherwise: macOS `/Applications` then `~/Applications`; Windows Program Files then `%LOCALAPPDATA%`; Linux `google-chrome`/`chromium` on PATH. `doctor` shows which.
|
|
188
190
|
- `BROWSER_AUTOMATION_PROFILE` — Chrome profile dir for `launch`. Default `~/.browser-automation/chrome-profile`; a profile still at the old location inside Chrome's own folder is moved there on launch (`browser-automation profile --migrate` to do it by hand).
|
|
189
191
|
- `BAC_SHOW_TAB=1` — `--show` on every `goto`/`new`: select the tab in its window when the automation Chrome is already in front (never raises Chrome over another app). macOS and Windows.
|
|
190
192
|
- `BAC_SESSION` — default session name for page commands.
|
package/dist/index.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
import updateNotifier from "update-notifier";
|
|
3
3
|
import { cli, define } from "gunshi";
|
|
4
4
|
import consola, { consola as consola$1 } from "consola";
|
|
5
|
-
import { homedir } from "node:os";
|
|
6
|
-
import { basename, dirname, extname, join, resolve } from "node:path";
|
|
7
|
-
import { appendFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
8
|
-
import { execFileSync, spawnSync } from "node:child_process";
|
|
5
|
+
import { homedir, tmpdir } from "node:os";
|
|
6
|
+
import { basename, delimiter, dirname, extname, join, resolve } from "node:path";
|
|
7
|
+
import { accessSync, appendFileSync, constants, existsSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { execFileSync, spawn, 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.19";
|
|
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,
|
|
@@ -957,7 +957,7 @@ function gatherEvidence() {
|
|
|
957
957
|
}
|
|
958
958
|
/** Where `launch` writes Chrome's stdout/stderr — Chrome logs the real reason there. */
|
|
959
959
|
function chromeLogPath() {
|
|
960
|
-
const tmp = process.env.TMPDIR?.replace(/\/$/, "") || "/tmp";
|
|
960
|
+
const tmp = process.platform === "win32" ? tmpdir() : process.env.TMPDIR?.replace(/\/$/, "") || "/tmp";
|
|
961
961
|
return process.env.BROWSER_AUTOMATION_LOG || `${tmp}/chrome-${targetPort()}.log`;
|
|
962
962
|
}
|
|
963
963
|
function probeLogPath() {
|
|
@@ -1689,7 +1689,7 @@ const snapshotCommand = define({
|
|
|
1689
1689
|
});
|
|
1690
1690
|
//#endregion
|
|
1691
1691
|
//#region src/commands/click.ts
|
|
1692
|
-
const sleep$
|
|
1692
|
+
const sleep$3 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1693
1693
|
const clickCommand = define({
|
|
1694
1694
|
name: "click",
|
|
1695
1695
|
description: "Click an element by ref (from the latest snapshot)",
|
|
@@ -1730,7 +1730,7 @@ const clickCommand = define({
|
|
|
1730
1730
|
while (Date.now() < focusDeadline) {
|
|
1731
1731
|
const f = await evalIn(`({f:document.hasFocus(),v:document.visibilityState})`);
|
|
1732
1732
|
if (f && f.f && f.v === "visible") break;
|
|
1733
|
-
await sleep$
|
|
1733
|
+
await sleep$3(50);
|
|
1734
1734
|
}
|
|
1735
1735
|
let prev = null;
|
|
1736
1736
|
let point = null;
|
|
@@ -1756,7 +1756,7 @@ const clickCommand = define({
|
|
|
1756
1756
|
x: a.x,
|
|
1757
1757
|
y: a.y
|
|
1758
1758
|
};
|
|
1759
|
-
await sleep$
|
|
1759
|
+
await sleep$3(60);
|
|
1760
1760
|
}
|
|
1761
1761
|
if (!point) {
|
|
1762
1762
|
consola$1.error(`<${ref}> not actionable for a trusted click: ${lastReason}`);
|
|
@@ -1771,7 +1771,7 @@ const clickCommand = define({
|
|
|
1771
1771
|
buttons: 0,
|
|
1772
1772
|
pointerType: "mouse"
|
|
1773
1773
|
});
|
|
1774
|
-
await sleep$
|
|
1774
|
+
await sleep$3(20);
|
|
1775
1775
|
await s.send("Input.dispatchMouseEvent", {
|
|
1776
1776
|
type: "mousePressed",
|
|
1777
1777
|
x,
|
|
@@ -1905,7 +1905,7 @@ const readCommand = define({
|
|
|
1905
1905
|
});
|
|
1906
1906
|
//#endregion
|
|
1907
1907
|
//#region src/commands/focus.ts
|
|
1908
|
-
const sleep$
|
|
1908
|
+
const sleep$2 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1909
1909
|
/**
|
|
1910
1910
|
* Make a tab believe it is the visible one.
|
|
1911
1911
|
*
|
|
@@ -1974,7 +1974,7 @@ const focusCommand = define({
|
|
|
1974
1974
|
returnByValue: true
|
|
1975
1975
|
})).result?.value ?? last;
|
|
1976
1976
|
if (last.focused && last.visibility === "visible") break;
|
|
1977
|
-
await sleep$
|
|
1977
|
+
await sleep$2(50);
|
|
1978
1978
|
}
|
|
1979
1979
|
return last;
|
|
1980
1980
|
});
|
|
@@ -2340,7 +2340,7 @@ const uploadCommand = define({
|
|
|
2340
2340
|
});
|
|
2341
2341
|
//#endregion
|
|
2342
2342
|
//#region src/commands/drop.ts
|
|
2343
|
-
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2343
|
+
const sleep$1 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2344
2344
|
/** Resolve each path to absolute and verify it's an existing file. */
|
|
2345
2345
|
function absFiles(paths) {
|
|
2346
2346
|
return paths.map((p) => {
|
|
@@ -2442,7 +2442,7 @@ const dropCommand = define({
|
|
|
2442
2442
|
while (Date.now() < focusDeadline) {
|
|
2443
2443
|
const f = await evalIn(`({f:document.hasFocus(),v:document.visibilityState})`);
|
|
2444
2444
|
if (f && f.f && f.v === "visible") break;
|
|
2445
|
-
await sleep(50);
|
|
2445
|
+
await sleep$1(50);
|
|
2446
2446
|
}
|
|
2447
2447
|
let prev = null;
|
|
2448
2448
|
let point = null;
|
|
@@ -2468,7 +2468,7 @@ const dropCommand = define({
|
|
|
2468
2468
|
x: a.x,
|
|
2469
2469
|
y: a.y
|
|
2470
2470
|
};
|
|
2471
|
-
await sleep(60);
|
|
2471
|
+
await sleep$1(60);
|
|
2472
2472
|
}
|
|
2473
2473
|
if (!point) {
|
|
2474
2474
|
consola$1.error(`<${ref}> not actionable for a drop: ${lastReason}`);
|
|
@@ -2492,7 +2492,7 @@ const dropCommand = define({
|
|
|
2492
2492
|
y,
|
|
2493
2493
|
data
|
|
2494
2494
|
});
|
|
2495
|
-
await sleep(20);
|
|
2495
|
+
await sleep$1(20);
|
|
2496
2496
|
await s.send("Input.dispatchDragEvent", {
|
|
2497
2497
|
type: "drop",
|
|
2498
2498
|
x,
|
|
@@ -2931,6 +2931,211 @@ function migrateProfile() {
|
|
|
2931
2931
|
};
|
|
2932
2932
|
}
|
|
2933
2933
|
//#endregion
|
|
2934
|
+
//#region src/core/chrome-path.ts
|
|
2935
|
+
function executable(p) {
|
|
2936
|
+
try {
|
|
2937
|
+
if (!statSync(p).isFile()) return false;
|
|
2938
|
+
if (process.platform === "win32") return true;
|
|
2939
|
+
accessSync(p, constants.X_OK);
|
|
2940
|
+
return true;
|
|
2941
|
+
} catch {
|
|
2942
|
+
return false;
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
const MAC_BINARY = join("Google Chrome.app", "Contents", "MacOS", "Google Chrome");
|
|
2946
|
+
function platformCandidates() {
|
|
2947
|
+
if (process.platform === "darwin") return [{
|
|
2948
|
+
path: join(process.env.BROWSER_AUTOMATION_TEST_SYSTEM_APPS || "/Applications", MAC_BINARY),
|
|
2949
|
+
source: "/Applications"
|
|
2950
|
+
}, {
|
|
2951
|
+
path: join(homedir(), "Applications", MAC_BINARY),
|
|
2952
|
+
source: "~/Applications"
|
|
2953
|
+
}];
|
|
2954
|
+
if (process.platform === "win32") {
|
|
2955
|
+
const out = [];
|
|
2956
|
+
const exe = join("Google", "Chrome", "Application", "chrome.exe");
|
|
2957
|
+
if (process.env.PROGRAMFILES) out.push({
|
|
2958
|
+
path: join(process.env.PROGRAMFILES, exe),
|
|
2959
|
+
source: "Program Files"
|
|
2960
|
+
});
|
|
2961
|
+
if (process.env["PROGRAMFILES(X86)"]) out.push({
|
|
2962
|
+
path: join(process.env["PROGRAMFILES(X86)"], exe),
|
|
2963
|
+
source: "Program Files (x86)"
|
|
2964
|
+
});
|
|
2965
|
+
if (process.env.LOCALAPPDATA) out.push({
|
|
2966
|
+
path: join(process.env.LOCALAPPDATA, exe),
|
|
2967
|
+
source: "%LOCALAPPDATA%"
|
|
2968
|
+
});
|
|
2969
|
+
return out;
|
|
2970
|
+
}
|
|
2971
|
+
const dirs = (process.env.PATH ?? "").split(delimiter).filter(Boolean);
|
|
2972
|
+
return [
|
|
2973
|
+
"google-chrome",
|
|
2974
|
+
"google-chrome-stable",
|
|
2975
|
+
"chromium",
|
|
2976
|
+
"chromium-browser"
|
|
2977
|
+
].flatMap((name) => dirs.map((d) => ({
|
|
2978
|
+
path: join(d, name),
|
|
2979
|
+
source: `PATH (${name})`
|
|
2980
|
+
})));
|
|
2981
|
+
}
|
|
2982
|
+
function chromeExecutable() {
|
|
2983
|
+
let ignored;
|
|
2984
|
+
for (const name of ["BROWSER_AUTOMATION_CHROME", "CHROME"]) {
|
|
2985
|
+
const v = process.env[name];
|
|
2986
|
+
if (!v) continue;
|
|
2987
|
+
if (executable(v)) return {
|
|
2988
|
+
path: v,
|
|
2989
|
+
source: name
|
|
2990
|
+
};
|
|
2991
|
+
ignored ??= `${name}=${v} is not an executable file`;
|
|
2992
|
+
}
|
|
2993
|
+
const hit = platformCandidates().find((c) => executable(c.path));
|
|
2994
|
+
return hit ? {
|
|
2995
|
+
path: hit.path,
|
|
2996
|
+
source: hit.source,
|
|
2997
|
+
ignored
|
|
2998
|
+
} : {
|
|
2999
|
+
path: null,
|
|
3000
|
+
source: "not found",
|
|
3001
|
+
ignored
|
|
3002
|
+
};
|
|
3003
|
+
}
|
|
3004
|
+
/** Where we looked, for a "not found" message. */
|
|
3005
|
+
function chromeSearchDescription() {
|
|
3006
|
+
if (process.platform === "darwin") return "/Applications and ~/Applications";
|
|
3007
|
+
if (process.platform === "win32") return "Program Files, Program Files (x86) and %LOCALAPPDATA%";
|
|
3008
|
+
return "google-chrome, google-chrome-stable, chromium and chromium-browser on PATH";
|
|
3009
|
+
}
|
|
3010
|
+
//#endregion
|
|
3011
|
+
//#region src/core/launch-windows.ts
|
|
3012
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
3013
|
+
/** chrome.exe — decided in one place for every platform (core/chrome-path.ts). */
|
|
3014
|
+
function windowsChromeExe() {
|
|
3015
|
+
return chromeExecutable().path;
|
|
3016
|
+
}
|
|
3017
|
+
/** Is anything answering CDP on this port? (The script's `is_up`.) */
|
|
3018
|
+
async function cdpUp(port) {
|
|
3019
|
+
try {
|
|
3020
|
+
return (await fetch(`http://127.0.0.1:${port}/json/version`, { signal: AbortSignal.timeout(2e3) })).ok;
|
|
3021
|
+
} catch {
|
|
3022
|
+
return false;
|
|
3023
|
+
}
|
|
3024
|
+
}
|
|
3025
|
+
/**
|
|
3026
|
+
* pid of OUR automation Chrome's browser process on this port, or 0.
|
|
3027
|
+
*
|
|
3028
|
+
* PowerShell for the command lines: Node cannot read another process's command
|
|
3029
|
+
* line on Windows, and `wmic` is gone from Windows 11 25H2.
|
|
3030
|
+
*/
|
|
3031
|
+
function ourChromePid(port) {
|
|
3032
|
+
const script = [
|
|
3033
|
+
"$ProgressPreference = 'SilentlyContinue'",
|
|
3034
|
+
`$re = '--remote-debugging-port=${port}(\\s|"|$)'`,
|
|
3035
|
+
"$sid = [System.Diagnostics.Process]::GetCurrentProcess().SessionId",
|
|
3036
|
+
"$b = Get-CimInstance Win32_Process -Filter \"Name = 'chrome.exe'\" |",
|
|
3037
|
+
" Where-Object { $_.SessionId -eq $sid -and $_.CommandLine -and $_.CommandLine -match $re -and $_.CommandLine -notmatch '--type=' } |",
|
|
3038
|
+
" Select-Object -First 1 -ExpandProperty ProcessId",
|
|
3039
|
+
"Write-Output ('BA-PID ' + [int]$b)"
|
|
3040
|
+
].join("\n");
|
|
3041
|
+
try {
|
|
3042
|
+
const out = execFileSync("powershell.exe", [
|
|
3043
|
+
"-NoProfile",
|
|
3044
|
+
"-NonInteractive",
|
|
3045
|
+
"-ExecutionPolicy",
|
|
3046
|
+
"Bypass",
|
|
3047
|
+
"-EncodedCommand",
|
|
3048
|
+
Buffer.from(script, "utf16le").toString("base64")
|
|
3049
|
+
], {
|
|
3050
|
+
encoding: "utf8",
|
|
3051
|
+
stdio: [
|
|
3052
|
+
"ignore",
|
|
3053
|
+
"pipe",
|
|
3054
|
+
"ignore"
|
|
3055
|
+
],
|
|
3056
|
+
timeout: 2e4,
|
|
3057
|
+
windowsHide: true
|
|
3058
|
+
});
|
|
3059
|
+
return Number(/^BA-PID (\d+)\s*$/m.exec(out)?.[1] ?? 0);
|
|
3060
|
+
} catch {
|
|
3061
|
+
return 0;
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
function alive(pid) {
|
|
3065
|
+
try {
|
|
3066
|
+
process.kill(pid, 0);
|
|
3067
|
+
return true;
|
|
3068
|
+
} catch {
|
|
3069
|
+
return false;
|
|
3070
|
+
}
|
|
3071
|
+
}
|
|
3072
|
+
/**
|
|
3073
|
+
* Quit OUR Chrome on this port and wait until it has really exited.
|
|
3074
|
+
*
|
|
3075
|
+
* CDP Browser.close first — Chrome's own quit, which flushes the profile that
|
|
3076
|
+
* holds the logins. On Windows the process does exit after it (unlike macOS,
|
|
3077
|
+
* where it lingers windowless). taskkill /F only if it will not go.
|
|
3078
|
+
*/
|
|
3079
|
+
async function stopOurChrome(port, say) {
|
|
3080
|
+
const pid = ourChromePid(port);
|
|
3081
|
+
if (!pid) return await cdpUp(port) ? "not-ours" : "none";
|
|
3082
|
+
await closeBrowser().catch(() => {});
|
|
3083
|
+
for (let i = 0; i < 40 && alive(pid); i++) await sleep(250);
|
|
3084
|
+
if (alive(pid)) {
|
|
3085
|
+
say(`Chrome (pid ${pid}) did not exit within 10s of being asked to quit; ending it.`);
|
|
3086
|
+
try {
|
|
3087
|
+
execFileSync("taskkill", [
|
|
3088
|
+
"/PID",
|
|
3089
|
+
String(pid),
|
|
3090
|
+
"/T",
|
|
3091
|
+
"/F"
|
|
3092
|
+
], { stdio: "ignore" });
|
|
3093
|
+
} catch {}
|
|
3094
|
+
for (let i = 0; i < 20 && alive(pid); i++) await sleep(250);
|
|
3095
|
+
}
|
|
3096
|
+
if (alive(pid)) throw new Error(`Chrome on :${port} (pid ${pid}) would not exit. Not relaunching on top of it.`);
|
|
3097
|
+
for (let i = 0; i < 20 && await cdpUp(port); i++) await sleep(250);
|
|
3098
|
+
return "stopped";
|
|
3099
|
+
}
|
|
3100
|
+
/** Start the automation Chrome unless ours is already serving the port. */
|
|
3101
|
+
async function startChrome(port, profile, log) {
|
|
3102
|
+
if (await cdpUp(port)) return ourChromePid(port) ? { outcome: "already-running" } : { outcome: "not-ours" };
|
|
3103
|
+
const exe = windowsChromeExe();
|
|
3104
|
+
if (!exe) return { outcome: "no-chrome" };
|
|
3105
|
+
mkdirSync(profile, { recursive: true });
|
|
3106
|
+
mkdirSync(dirname(log), { recursive: true });
|
|
3107
|
+
try {
|
|
3108
|
+
if (statSync(log).size > 0) renameSync(log, `${log}.prev`);
|
|
3109
|
+
} catch {}
|
|
3110
|
+
const fd = openSync(log, "a");
|
|
3111
|
+
spawn(exe, [
|
|
3112
|
+
`--remote-debugging-port=${port}`,
|
|
3113
|
+
`--user-data-dir=${profile}`,
|
|
3114
|
+
"--no-first-run",
|
|
3115
|
+
"--no-default-browser-check",
|
|
3116
|
+
"about:blank"
|
|
3117
|
+
], {
|
|
3118
|
+
detached: true,
|
|
3119
|
+
stdio: [
|
|
3120
|
+
"ignore",
|
|
3121
|
+
fd,
|
|
3122
|
+
fd
|
|
3123
|
+
]
|
|
3124
|
+
}).unref();
|
|
3125
|
+
const started = Date.now();
|
|
3126
|
+
for (let i = 0; i < 240; i++) {
|
|
3127
|
+
if (await cdpUp(port)) return {
|
|
3128
|
+
outcome: "launched",
|
|
3129
|
+
seconds: Math.round((Date.now() - started) / 1e3)
|
|
3130
|
+
};
|
|
3131
|
+
await sleep(250);
|
|
3132
|
+
}
|
|
3133
|
+
return {
|
|
3134
|
+
outcome: "timeout",
|
|
3135
|
+
log
|
|
3136
|
+
};
|
|
3137
|
+
}
|
|
3138
|
+
//#endregion
|
|
2934
3139
|
//#region src/commands/launch.ts
|
|
2935
3140
|
const launchCommand = define({
|
|
2936
3141
|
name: "launch",
|
|
@@ -2946,35 +3151,46 @@ const launchCommand = define({
|
|
|
2946
3151
|
}
|
|
2947
3152
|
},
|
|
2948
3153
|
async run(ctx) {
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
3154
|
+
if (process.platform === "win32") {
|
|
3155
|
+
if (!await launchWindows(ctx.values.status === true, ctx.values.restart === true)) process.exit(1);
|
|
3156
|
+
if (ctx.values.status) return;
|
|
3157
|
+
} else {
|
|
3158
|
+
const script = launchScriptPath();
|
|
3159
|
+
if (!existsSync(script)) {
|
|
3160
|
+
consola$1.error(`launch-chrome.sh not found at ${script}. Reinstall the package.`);
|
|
3161
|
+
process.exit(1);
|
|
3162
|
+
}
|
|
3163
|
+
const port = ["--port", String(cdpPort())];
|
|
3164
|
+
const bash = (extra) => spawnSync("bash", [
|
|
3165
|
+
script,
|
|
3166
|
+
...port,
|
|
3167
|
+
...extra
|
|
3168
|
+
], { stdio: "inherit" });
|
|
3169
|
+
if (ctx.values.status) process.exit(bash(["--status"]).status ?? 1);
|
|
3170
|
+
if (ctx.values.restart) {
|
|
3171
|
+
const tabs = await listPageTargets().then((t) => t.length).catch(() => null);
|
|
3172
|
+
if (tabs !== null) consola$1.info(`Restarting Chrome on :${cdpPort()} — closing ${tabs} open tab(s).`);
|
|
3173
|
+
await closeBrowser().catch(() => {});
|
|
3174
|
+
const stop = bash([
|
|
3175
|
+
"--stop",
|
|
3176
|
+
"--profile",
|
|
3177
|
+
resolveProfile().dir
|
|
3178
|
+
]);
|
|
3179
|
+
if (stop.status !== 0) process.exit(stop.status ?? 1);
|
|
3180
|
+
}
|
|
3181
|
+
const m = migrateProfile();
|
|
3182
|
+
if (m.outcome === "moved") consola$1.success(`Profile ${m.detail} — logins travel with it.`);
|
|
3183
|
+
else if (m.outcome === "refused" || m.outcome === "failed") consola$1.warn(`Profile not moved: ${m.detail}`);
|
|
3184
|
+
else if (m.outcome === "in-use") consola$1.info(`Profile not moved yet: ${m.detail}`);
|
|
3185
|
+
const chrome = chromeExecutable();
|
|
3186
|
+
if (chrome.ignored) consola$1.warn(`Ignoring ${chrome.ignored}.`);
|
|
3187
|
+
const r = bash([
|
|
2967
3188
|
"--profile",
|
|
2968
|
-
|
|
3189
|
+
m.dir,
|
|
3190
|
+
...chrome.path ? ["--chrome", chrome.path] : []
|
|
2969
3191
|
]);
|
|
2970
|
-
if (
|
|
3192
|
+
if (r.status !== 0) process.exit(r.status ?? 1);
|
|
2971
3193
|
}
|
|
2972
|
-
const m = migrateProfile();
|
|
2973
|
-
if (m.outcome === "moved") consola$1.success(`Profile ${m.detail} — logins travel with it.`);
|
|
2974
|
-
else if (m.outcome === "refused" || m.outcome === "failed") consola$1.warn(`Profile not moved: ${m.detail}`);
|
|
2975
|
-
else if (m.outcome === "in-use") consola$1.info(`Profile not moved yet: ${m.detail}`);
|
|
2976
|
-
const r = bash(["--profile", m.dir]);
|
|
2977
|
-
if (r.status !== 0) process.exit(r.status ?? 1);
|
|
2978
3194
|
const health = await probeRenderer().catch((e) => ({
|
|
2979
3195
|
ok: false,
|
|
2980
3196
|
ms: 0,
|
|
@@ -2995,6 +3211,56 @@ const launchCommand = define({
|
|
|
2995
3211
|
process.exit(1);
|
|
2996
3212
|
}
|
|
2997
3213
|
});
|
|
3214
|
+
/**
|
|
3215
|
+
* Windows: the launch script's contract in TypeScript. Prints the same lines
|
|
3216
|
+
* the script prints, so an agent reading either learns the same thing.
|
|
3217
|
+
* Returns false on a failure that must stop `launch` before the health check.
|
|
3218
|
+
*/
|
|
3219
|
+
async function launchWindows(statusOnly, restart) {
|
|
3220
|
+
const port = cdpPort();
|
|
3221
|
+
if (statusOnly) {
|
|
3222
|
+
const up = await cdpUp(port);
|
|
3223
|
+
consola$1.log(up ? `Chrome CDP on :${port} is up` : `Chrome CDP on :${port} is NOT running`);
|
|
3224
|
+
return up;
|
|
3225
|
+
}
|
|
3226
|
+
if (restart) {
|
|
3227
|
+
const tabs = await listPageTargets().then((t) => t.length).catch(() => null);
|
|
3228
|
+
if (tabs !== null) consola$1.info(`Restarting Chrome on :${port} — closing ${tabs} open tab(s).`);
|
|
3229
|
+
try {
|
|
3230
|
+
if (await stopOurChrome(port, (s) => consola$1.warn(s)) === "not-ours") {
|
|
3231
|
+
consola$1.error(`Refusing to restart a Chrome this account did not start (something else serves :${port}).`);
|
|
3232
|
+
return false;
|
|
3233
|
+
}
|
|
3234
|
+
} catch (e) {
|
|
3235
|
+
consola$1.error(String(e?.message ?? e));
|
|
3236
|
+
return false;
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
const m = migrateProfile();
|
|
3240
|
+
if (m.outcome === "moved") consola$1.success(`Profile ${m.detail} — logins travel with it.`);
|
|
3241
|
+
else if (m.outcome === "refused" || m.outcome === "failed") consola$1.warn(`Profile not moved: ${m.detail}`);
|
|
3242
|
+
const r = await startChrome(port, m.dir, chromeLogPath());
|
|
3243
|
+
switch (r.outcome) {
|
|
3244
|
+
case "already-running":
|
|
3245
|
+
consola$1.log(`Already running on :${port} — the port is held.`);
|
|
3246
|
+
consola$1.log("Drive it with: browser-automation goto -s <session> <url>");
|
|
3247
|
+
consola$1.log("(Port held is not health. Check it works: browser-automation doctor)");
|
|
3248
|
+
return true;
|
|
3249
|
+
case "launched":
|
|
3250
|
+
consola$1.log(`Chrome launched on :${port} in ${r.seconds}s (profile: ${m.dir}, log: ${chromeLogPath()})`);
|
|
3251
|
+
consola$1.log("Drive it with: browser-automation goto -s <session> <url>");
|
|
3252
|
+
return true;
|
|
3253
|
+
case "not-ours":
|
|
3254
|
+
consola$1.error(`Something on this computer is already serving CDP on port ${port}, and it is not a Chrome this account started. Driving it would act in ANOTHER user's browser — quit Chrome in that account, or set BROWSER_AUTOMATION_PORT to a free port for this one.`);
|
|
3255
|
+
return false;
|
|
3256
|
+
case "no-chrome":
|
|
3257
|
+
consola$1.error("Chrome not found (looked in Program Files, Program Files (x86) and %LOCALAPPDATA%). Install it — winget install --id Google.Chrome -e — or set BROWSER_AUTOMATION_CHROME to chrome.exe.");
|
|
3258
|
+
return false;
|
|
3259
|
+
case "timeout":
|
|
3260
|
+
consola$1.error(`Chrome did not serve CDP on :${port} within 60s. Chrome's log: ${r.log}`);
|
|
3261
|
+
return false;
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
2998
3264
|
//#endregion
|
|
2999
3265
|
//#region src/commands/doctor.ts
|
|
3000
3266
|
/**
|
|
@@ -3038,6 +3304,10 @@ const doctorCommand = define({
|
|
|
3038
3304
|
consola$1.log(` ⚠ still inside Chrome's own folder, which an app-hosted session may be refused.`);
|
|
3039
3305
|
consola$1.log(` Move it (logins included): browser-automation profile --migrate`);
|
|
3040
3306
|
}
|
|
3307
|
+
const chrome = chromeExecutable();
|
|
3308
|
+
if (chrome.path) consola$1.log(` • Chrome binary: ${chrome.path} (${chrome.source})`);
|
|
3309
|
+
else bad(`Chrome binary: not found (looked in ${chromeSearchDescription()}) — \`launch\` cannot start one. Install Chrome, or set CHROME.`);
|
|
3310
|
+
if (chrome.ignored) consola$1.log(` ⚠ ignoring ${chrome.ignored}`);
|
|
3041
3311
|
let version;
|
|
3042
3312
|
try {
|
|
3043
3313
|
version = await (await fetch(`${cdpHost()}/json/version`)).json();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@generativereality/browser-automation",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.19",
|
|
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": {
|
package/scripts/launch-chrome.sh
CHANGED
|
@@ -56,6 +56,7 @@ ask_cli_for_port() {
|
|
|
56
56
|
|
|
57
57
|
PORT=""
|
|
58
58
|
PROFILE=""
|
|
59
|
+
CHROME_ARG=""
|
|
59
60
|
RESTART=0
|
|
60
61
|
STOP_ONLY=0
|
|
61
62
|
ARGS=()
|
|
@@ -63,6 +64,7 @@ while [ $# -gt 0 ]; do
|
|
|
63
64
|
case "$1" in
|
|
64
65
|
--port) PORT="${2:-}"; shift 2 ;;
|
|
65
66
|
--profile) PROFILE="${2:-}"; shift 2 ;;
|
|
67
|
+
--chrome) CHROME_ARG="${2:-}"; shift 2 ;;
|
|
66
68
|
--restart) RESTART=1; shift ;;
|
|
67
69
|
# Quit our Chrome and stop there. `launch --restart` uses it so the profile
|
|
68
70
|
# can be moved while nothing has it open, before the relaunch.
|
|
@@ -227,22 +229,41 @@ if is_up; then
|
|
|
227
229
|
exit 0
|
|
228
230
|
fi
|
|
229
231
|
|
|
230
|
-
# Resolve Chrome binary
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
232
|
+
# Resolve the Chrome binary. **Asked for, like the port and the profile**:
|
|
233
|
+
# `chromeExecutable()` in src/core/chrome-path.ts decides, and `launch` passes it
|
|
234
|
+
# with --chrome. The order below only repeats it for a person running this by
|
|
235
|
+
# hand: an explicit $BROWSER_AUTOMATION_CHROME / $CHROME that is executable, then
|
|
236
|
+
# /Applications, then ~/Applications.
|
|
237
|
+
#
|
|
238
|
+
# This used to hardcode /Applications/Google Chrome.app and OVERWRITE $CHROME, so
|
|
239
|
+
# a Chrome in ~/Applications — where Mind My Money installs it for an account
|
|
240
|
+
# that cannot write /Applications — could not be launched at all (2026-10-05).
|
|
241
|
+
CHROME_FROM_ENV="${CHROME:-}" # read BEFORE reusing the name below
|
|
242
|
+
CHROME=""
|
|
243
|
+
for c in "$CHROME_ARG" "${BROWSER_AUTOMATION_CHROME:-}" "$CHROME_FROM_ENV"; do
|
|
244
|
+
if [ -n "$c" ] && [ -x "$c" ] && [ ! -d "$c" ]; then CHROME="$c"; break; fi
|
|
245
|
+
done
|
|
246
|
+
if [ -z "$CHROME" ]; then
|
|
247
|
+
case "$(uname -s)" in
|
|
248
|
+
Darwin)
|
|
249
|
+
for c in "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
|
|
250
|
+
"$HOME/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; do
|
|
251
|
+
if [ -x "$c" ]; then CHROME="$c"; break; fi
|
|
252
|
+
done
|
|
253
|
+
;;
|
|
254
|
+
Linux)
|
|
255
|
+
CHROME="$(command -v google-chrome || command -v google-chrome-stable || command -v chromium || command -v chromium-browser || true)"
|
|
256
|
+
;;
|
|
257
|
+
*)
|
|
258
|
+
echo "Error: this script is for macOS and Linux (got $(uname -s)). On Windows, run \`browser-automation launch\` — it does not use this script." >&2
|
|
259
|
+
exit 1
|
|
260
|
+
;;
|
|
261
|
+
esac
|
|
262
|
+
fi
|
|
243
263
|
|
|
244
|
-
if [ ! -x "$CHROME" ]; then
|
|
245
|
-
echo "Error: Chrome not found
|
|
264
|
+
if [ -z "$CHROME" ] || [ ! -x "$CHROME" ]; then
|
|
265
|
+
echo "Error: Chrome not found (looked in /Applications and ~/Applications on macOS, PATH on Linux)." >&2
|
|
266
|
+
echo " Install it, or set CHROME=/path/to/chrome if it lives elsewhere." >&2
|
|
246
267
|
exit 1
|
|
247
268
|
fi
|
|
248
269
|
|
package/skills/browser/SKILL.md
CHANGED
|
@@ -286,9 +286,15 @@ There's no `state-save`/`state-load` to manage — the profile *is* the auth sto
|
|
|
286
286
|
- **Page still loading.** `goto` waits for the load event, but SPAs render after.
|
|
287
287
|
If a `read`/`snapshot` looks empty, re-run after a moment, or snapshot again
|
|
288
288
|
once a known element should be present.
|
|
289
|
-
- **`launch`
|
|
290
|
-
|
|
291
|
-
|
|
289
|
+
- **`launch` works on macOS, Linux and Windows.** On Windows it needs only Node
|
|
290
|
+
(no Git Bash): it finds `chrome.exe` in Program Files or `%LOCALAPPDATA%`
|
|
291
|
+
(override with `BROWSER_AUTOMATION_CHROME`), uses the same profile
|
|
292
|
+
(`%USERPROFILE%\.browser-automation\chrome-profile`) and the same rules —
|
|
293
|
+
idempotent, refuses a port held by a Chrome this account did not start, and
|
|
294
|
+
`--restart` quits Chrome cleanly so the logins survive. ⛔ So do not start
|
|
295
|
+
Chrome by hand on Windows any more; that was the workaround for CLIs older than
|
|
296
|
+
0.4.18, which refused with `unsupported OS MINGW64_NT`. A cold start brings
|
|
297
|
+
Chrome to the front once, on every platform.
|
|
292
298
|
|
|
293
299
|
## Network insights — find the API behind a page
|
|
294
300
|
|
|
@@ -327,6 +333,13 @@ code lives, how to validate with `node dist/index.js`, and the PR steps:
|
|
|
327
333
|
|
|
328
334
|
## Troubleshooting
|
|
329
335
|
|
|
336
|
+
- **Which Chrome `launch` starts:** `CHROME` / `BROWSER_AUTOMATION_CHROME` when it
|
|
337
|
+
points at an executable; otherwise macOS `/Applications` then **`~/Applications`**
|
|
338
|
+
(where an account that cannot write `/Applications` gets Chrome installed),
|
|
339
|
+
Windows Program Files then the per-user `%LOCALAPPDATA%` install, Linux
|
|
340
|
+
`google-chrome`/`chromium` on PATH. `doctor` prints the one it found — check that
|
|
341
|
+
line before concluding "Chrome is not installed". Before 0.4.19 the macOS launcher
|
|
342
|
+
only knew `/Applications` and ignored `CHROME`.
|
|
330
343
|
- **`No CDP browser on http://localhost:<port>`** → `browser-automation launch`.
|
|
331
344
|
If it says the port is held by ANOTHER user, that is not your Chrome and
|
|
332
345
|
driving it would act in their session — quit Chrome in that account, or set
|