@generativereality/browser-automation 0.4.16 → 0.4.17
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 +1 -1
- package/dist/index.js +69 -2
- package/package.json +1 -1
- package/skills/browser/SKILL.md +4 -2
|
@@ -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.17",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "generativereality"
|
|
7
7
|
},
|
package/README.md
CHANGED
|
@@ -186,7 +186,7 @@ same one-action-per-snapshot rule as Playwright refs.
|
|
|
186
186
|
`doctor` prints it too, and warns if another user holds it.
|
|
187
187
|
- `BROWSER_AUTOMATION_CDP` — full CDP host, overriding the port entirely.
|
|
188
188
|
- `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
|
-
- `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).
|
|
189
|
+
- `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
190
|
- `BAC_SESSION` — default session name for page commands.
|
|
191
191
|
|
|
192
192
|
## License
|
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.17";
|
|
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,
|
|
@@ -1098,6 +1098,68 @@ async function withRendererDiagnosis(fn) {
|
|
|
1098
1098
|
}
|
|
1099
1099
|
}
|
|
1100
1100
|
//#endregion
|
|
1101
|
+
//#region src/core/windows-foreground.ts
|
|
1102
|
+
/** The script, with the port substituted. Exported so the test can read it. */
|
|
1103
|
+
function probeScript(port) {
|
|
1104
|
+
return [
|
|
1105
|
+
"$ErrorActionPreference = 'Stop'",
|
|
1106
|
+
"$ProgressPreference = 'SilentlyContinue'",
|
|
1107
|
+
"Add-Type -Namespace BrowserAutomation -Name User32 -MemberDefinition @'",
|
|
1108
|
+
"[DllImport(\"user32.dll\")] public static extern System.IntPtr GetForegroundWindow();",
|
|
1109
|
+
"[DllImport(\"user32.dll\")] public static extern uint GetWindowThreadProcessId(System.IntPtr hWnd, out uint processId);",
|
|
1110
|
+
"'@",
|
|
1111
|
+
"$U = [BrowserAutomation.User32]",
|
|
1112
|
+
"$h = $U::GetForegroundWindow()",
|
|
1113
|
+
"$fg = [uint32]0",
|
|
1114
|
+
"if ($h -ne [IntPtr]::Zero) { [void]$U::GetWindowThreadProcessId($h, [ref]$fg) }",
|
|
1115
|
+
`$re = '--remote-debugging-port=${port}(\\s|"|$)'`,
|
|
1116
|
+
"$sid = [System.Diagnostics.Process]::GetCurrentProcess().SessionId",
|
|
1117
|
+
"$b = Get-CimInstance Win32_Process -Filter \"Name = 'chrome.exe'\" |",
|
|
1118
|
+
" Where-Object { $_.SessionId -eq $sid -and $_.CommandLine -and $_.CommandLine -match $re -and $_.CommandLine -notmatch '--type=' } |",
|
|
1119
|
+
" Select-Object -First 1 -ExpandProperty ProcessId",
|
|
1120
|
+
"Write-Output ('BA-FG ' + $fg + ' ' + [int]$b)"
|
|
1121
|
+
].join("\n");
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Read the answer out of PowerShell's stdout.
|
|
1125
|
+
*
|
|
1126
|
+
* Scans for the line with the expected SHAPE rather than taking the first line:
|
|
1127
|
+
* a PowerShell child process can put other things on its streams (CLIXML
|
|
1128
|
+
* progress records, "Preparing modules for first use"), and keying on line one
|
|
1129
|
+
* is how a parser starts failing the day something precedes the answer.
|
|
1130
|
+
*/
|
|
1131
|
+
function parseProbe(stdout) {
|
|
1132
|
+
const m = /^BA-FG (\d+) (\d+)\s*$/m.exec(stdout);
|
|
1133
|
+
return m ? {
|
|
1134
|
+
foreground: Number(m[1]),
|
|
1135
|
+
browser: Number(m[2])
|
|
1136
|
+
} : null;
|
|
1137
|
+
}
|
|
1138
|
+
function windowsForeground(port) {
|
|
1139
|
+
const encoded = Buffer.from(probeScript(port), "utf16le").toString("base64");
|
|
1140
|
+
try {
|
|
1141
|
+
return parseProbe(execFileSync("powershell.exe", [
|
|
1142
|
+
"-NoProfile",
|
|
1143
|
+
"-NonInteractive",
|
|
1144
|
+
"-ExecutionPolicy",
|
|
1145
|
+
"Bypass",
|
|
1146
|
+
"-EncodedCommand",
|
|
1147
|
+
encoded
|
|
1148
|
+
], {
|
|
1149
|
+
encoding: "utf8",
|
|
1150
|
+
stdio: [
|
|
1151
|
+
"ignore",
|
|
1152
|
+
"pipe",
|
|
1153
|
+
"ignore"
|
|
1154
|
+
],
|
|
1155
|
+
timeout: 15e3,
|
|
1156
|
+
windowsHide: true
|
|
1157
|
+
}));
|
|
1158
|
+
} catch {
|
|
1159
|
+
return null;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
//#endregion
|
|
1101
1163
|
//#region src/core/show.ts
|
|
1102
1164
|
/** On for this command: `--show`, or `BAC_SHOW_TAB=1` set once by a skill. */
|
|
1103
1165
|
function wantsShow(flag) {
|
|
@@ -1113,6 +1175,11 @@ function wantsShow(flag) {
|
|
|
1113
1175
|
function ourChromeIsFrontmost() {
|
|
1114
1176
|
const injected = process.env.BROWSER_AUTOMATION_TEST_FRONTMOST;
|
|
1115
1177
|
if (injected) return injected === "chrome";
|
|
1178
|
+
if (process.platform === "win32") {
|
|
1179
|
+
const w = windowsForeground(targetPort());
|
|
1180
|
+
if (!w || !w.foreground || !w.browser) return null;
|
|
1181
|
+
return w.foreground === w.browser;
|
|
1182
|
+
}
|
|
1116
1183
|
if (process.platform !== "darwin") return null;
|
|
1117
1184
|
try {
|
|
1118
1185
|
const asn = execFileSync("lsappinfo", ["front"], {
|
|
@@ -1156,7 +1223,7 @@ async function showTab(targetId) {
|
|
|
1156
1223
|
/** One line for the agent when it asked and did not get it — never silent, never loud. */
|
|
1157
1224
|
function describeNotShown(outcome) {
|
|
1158
1225
|
if (outcome === "not-frontmost") return "Tab not shown: another app (or another Chrome) is in front, and --show never brings this Chrome over it. It selects the tab once the automation Chrome is in front.";
|
|
1159
|
-
if (outcome === "unsupported") return "Tab not shown: cannot tell which app is in front here (macOS
|
|
1226
|
+
if (outcome === "unsupported") return "Tab not shown: cannot tell which app is in front here (supported on macOS and Windows), so --show did nothing rather than risk taking the screen.";
|
|
1160
1227
|
return null;
|
|
1161
1228
|
}
|
|
1162
1229
|
//#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.17",
|
|
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/skills/browser/SKILL.md
CHANGED
|
@@ -62,8 +62,10 @@ file under `~/.browser-automation/sessions/`.
|
|
|
62
62
|
case of someone watching it. The person's everyday Chrome counts as "another
|
|
63
63
|
app": it is checked by process, not by name. ⛔ Do not reach for `focus --raise`
|
|
64
64
|
to "make it show" — that is the screen-taking version; keep it for the moments
|
|
65
|
-
a person must look (a sign-in, a CAPTCHA). macOS
|
|
66
|
-
reports that it cannot tell and does nothing.
|
|
65
|
+
a person must look (a sign-in, a CAPTCHA). **macOS and Windows**; on Linux
|
|
66
|
+
`--show` reports that it cannot tell and does nothing. On Windows each
|
|
67
|
+
`--show` costs about 0.9 s (a PowerShell probe of the foreground window), so
|
|
68
|
+
turn it on where someone may be watching, not by reflex for batch work.
|
|
67
69
|
- **Self-healing.** If the tab was closed (or Chrome restarted and reissued
|
|
68
70
|
targetIds), the next `goto` just opens a fresh background tab for that session.
|
|
69
71
|
- **Refs live in the DOM.** `snapshot` stamps `data-ba-ref="e7"` onto each
|