@generativereality/browser-automation 0.3.2 → 0.4.0

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.3.2",
4
+ "version": "0.4.0",
5
5
  "author": {
6
6
  "name": "generativereality"
7
7
  },
package/README.md CHANGED
@@ -96,6 +96,7 @@ browser-automation bind -s bank -m nordnet # …or adopt it into a session
96
96
  | `eval (-s\|-m\|-t) <js>` | Evaluate a JS expression in the tab (escape hatch) |
97
97
  | `download (-s\|-m\|-t) (--click <ref>\|--url <href>)` | Capture a file/CSV download, wait for completion, print the path |
98
98
  | `network (-s\|-m\|-t) [--reload\|--click\|--nav] [--filter --headers --body]` | Capture network requests (find the API, headers, response bodies) |
99
+ | `screenshot (-s\|-m\|-t) [--full] [-o path]` | Save a PNG screenshot (viewport or full page) |
99
100
  | `close (-s\|-m\|-t) [--tab]` | Forget the session (tab stays open); `--tab` also closes the browser tab |
100
101
 
101
102
  ## How refs work
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, s
7
7
  import { spawnSync } from "node:child_process";
8
8
  import { fileURLToPath } from "node:url";
9
9
  //#region package.json
10
- var version = "0.3.2";
10
+ var version = "0.4.0";
11
11
  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.";
12
12
  //#endregion
13
13
  //#region src/core/session.ts
@@ -202,6 +202,16 @@ async function evaluateUntil(targetId, expression, ready, { timeout = 5e3, inter
202
202
  }
203
203
  return last;
204
204
  }
205
+ /** Capture a PNG screenshot of a page target (optionally the full page). */
206
+ async function captureScreenshot(targetId, { fullPage = false } = {}) {
207
+ return withPage(targetId, async (s) => {
208
+ const r = await s.send("Page.captureScreenshot", {
209
+ format: "png",
210
+ captureBeyondViewport: fullPage
211
+ });
212
+ return Buffer.from(r.data, "base64");
213
+ });
214
+ }
205
215
  /** Navigate a page target and wait for load (or timeout). */
206
216
  async function navigate(targetId, url, { timeout = 3e4 } = {}) {
207
217
  return withPage(targetId, async (s) => {
@@ -656,7 +666,7 @@ function urlTriggerExpr(url) {
656
666
  }
657
667
  //#endregion
658
668
  //#region src/commands/download.ts
659
- const DEFAULT_DIR = join(homedir(), ".browser-automation", "downloads");
669
+ const DEFAULT_DIR$1 = join(homedir(), ".browser-automation", "downloads");
660
670
  const downloadCommand = define({
661
671
  name: "download",
662
672
  description: "Capture a file download (e.g. a CSV export): trigger it with --click <ref> or --url, wait for completion",
@@ -673,7 +683,7 @@ const downloadCommand = define({
673
683
  dir: {
674
684
  type: "string",
675
685
  short: "d",
676
- description: `Directory to save into (default: ${DEFAULT_DIR})`
686
+ description: `Directory to save into (default: ${DEFAULT_DIR$1})`
677
687
  },
678
688
  timeout: {
679
689
  type: "number",
@@ -691,7 +701,7 @@ const downloadCommand = define({
691
701
  consola.error(`--click expects a ref like e42 (run snapshot first)`);
692
702
  process.exit(1);
693
703
  }
694
- const r = await captureDownload(await resolveExistingTargetId(targetOpts(ctx.values)), ctx.values.dir || DEFAULT_DIR, click ? clickTriggerExpr(click) : urlTriggerExpr(url), ctx.values.timeout ?? 3e4);
704
+ const r = await captureDownload(await resolveExistingTargetId(targetOpts(ctx.values)), ctx.values.dir || DEFAULT_DIR$1, click ? clickTriggerExpr(click) : urlTriggerExpr(url), ctx.values.timeout ?? 3e4);
695
705
  consola.success(`Downloaded ${r.filename} (${r.bytes} bytes)`);
696
706
  process.stdout.write(r.path + "\n");
697
707
  }
@@ -834,6 +844,37 @@ const networkCommand = define({
834
844
  }
835
845
  });
836
846
  //#endregion
847
+ //#region src/commands/screenshot.ts
848
+ const DEFAULT_DIR = join(homedir(), ".browser-automation", "screenshots");
849
+ const screenshotCommand = define({
850
+ name: "screenshot",
851
+ description: "Save a PNG screenshot of a tab (--full for the whole page)",
852
+ args: {
853
+ ...targetArgs,
854
+ out: {
855
+ type: "string",
856
+ short: "o",
857
+ description: "Output file path (default: ~/.browser-automation/screenshots/<ts>.png)"
858
+ },
859
+ full: {
860
+ type: "boolean",
861
+ description: "Capture the full scrollable page, not just the viewport"
862
+ }
863
+ },
864
+ async run(ctx) {
865
+ const targetId = await resolveExistingTargetId(targetOpts(ctx.values));
866
+ const png = await captureScreenshot(targetId, { fullPage: ctx.values.full });
867
+ let out = ctx.values.out;
868
+ if (!out) {
869
+ mkdirSync(DEFAULT_DIR, { recursive: true });
870
+ out = join(DEFAULT_DIR, `${((await listPageTargets()).find((p) => p.id === targetId)?.title || "page").replace(/[^a-z0-9]+/gi, "-").replace(/^-|-$/g, "").slice(0, 40) || "page"}.png`);
871
+ }
872
+ writeFileSync(out, png);
873
+ consola.success(`Saved screenshot (${png.length} bytes)`);
874
+ process.stdout.write(out + "\n");
875
+ }
876
+ });
877
+ //#endregion
837
878
  //#region src/commands/list.ts
838
879
  const listCommand = define({
839
880
  name: "list",
@@ -1024,6 +1065,8 @@ const subCommands = new Map([
1024
1065
  ["eval", evalCommand],
1025
1066
  ["download", downloadCommand],
1026
1067
  ["network", networkCommand],
1068
+ ["screenshot", screenshotCommand],
1069
+ ["shot", screenshotCommand],
1027
1070
  ["list", listCommand],
1028
1071
  ["ls", listCommand],
1029
1072
  ["close", closeCommand],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@generativereality/browser-automation",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
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": {
@@ -84,6 +84,7 @@ Page commands take a tab selector — `-s <session>` (default `$BAC_SESSION`, el
84
84
  | Evaluate JS in the tab (escape hatch) | `browser-automation eval -m op.fi 'document.title'` |
85
85
  | Download a file / CSV export | `browser-automation download -m bank --click e42` (or `--url <href>`) |
86
86
  | Inspect network (find the API, headers, bodies) | `browser-automation network -m bank --reload --filter api --headers --body` |
87
+ | Screenshot a tab | `browser-automation screenshot -m op.fi --full -o shot.png` |
87
88
  | Forget a session (tab stays open) | `browser-automation close -s work` |
88
89
  | Forget **and** close the browser tab | `browser-automation close -s work --tab` |
89
90