agent-browser 0.31.0 → 0.31.2

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/README.md CHANGED
@@ -689,6 +689,8 @@ agent-browser --session "$SESSION" --restore open twitter.com
689
689
  agent-browser --session "$SESSION" --restore --restore-check-text Dashboard open twitter.com
690
690
  ```
691
691
 
692
+ State is saved when the browser closes (explicit `close`, idle timeout, or daemon shutdown) and also periodically while the browser is open, so a browser window you close by hand still leaves a recent save behind. Periodic autosave waits for commands to settle, then saves at most once per `AGENT_BROWSER_AUTOSAVE_INTERVAL_MS` (default 30000; set to `0` to save only on close). Idle sessions keep saving on the same interval, so changes the page makes on its own (token refreshes, background requests) are captured too. It respects the `--restore-save` policy.
693
+
692
694
  ### State Encryption
693
695
 
694
696
  Encrypt saved session data at rest with AES-256-GCM:
@@ -705,6 +707,7 @@ agent-browser --session secure --restore open example.com
705
707
  | --------------------------------- | -------------------------------------------------- |
706
708
  | `AGENT_BROWSER_RESTORE` | Auto-save/load state persistence name |
707
709
  | `AGENT_BROWSER_RESTORE_SAVE` | Restore save policy: `auto`, `always`, or `never` |
710
+ | `AGENT_BROWSER_AUTOSAVE_INTERVAL_MS` | Min ms between periodic autosaves (default: 30000, 0 disables) |
708
711
  | `AGENT_BROWSER_NAMESPACE` | Namespace for daemon sockets and restore state |
709
712
  | `AGENT_BROWSER_SESSION_NAME` | Legacy auto-save/load state persistence name |
710
713
  | `AGENT_BROWSER_ENCRYPTION_KEY` | 64-char hex key for AES-256-GCM encryption |
@@ -900,6 +903,7 @@ This is useful for multimodal AI models that can reason about visual layout, unl
900
903
  | `--screenshot-quality <n>` | JPEG quality 0-100 (or `AGENT_BROWSER_SCREENSHOT_QUALITY` env) |
901
904
  | `--screenshot-format <fmt>` | Screenshot format: `png`, `jpeg` (or `AGENT_BROWSER_SCREENSHOT_FORMAT` env) |
902
905
  | `--headed` | Show browser window (not headless) (or `AGENT_BROWSER_HEADED` env) |
906
+ | `--webgpu` | Enable WebGPU; SwiftShader software Vulkan on Linux, no GPU required (or `AGENT_BROWSER_WEBGPU` env) |
903
907
  | `--cdp <port\|url>` | Connect via Chrome DevTools Protocol (port or WebSocket URL) |
904
908
  | `--auto-connect` | Auto-discover and connect to running Chrome (or `AGENT_BROWSER_AUTO_CONNECT` env) |
905
909
  | `--color-scheme <scheme>` | Color scheme: `dark`, `light`, `no-preference` (or `AGENT_BROWSER_COLOR_SCHEME` env) |
@@ -1148,8 +1152,41 @@ agent-browser open example.com --headed
1148
1152
 
1149
1153
  This opens a visible browser window instead of running headless.
1150
1154
 
1155
+ On Linux hosts with no display (servers, containers), `--headed` still works: when `DISPLAY` is unset and Xvfb is installed, agent-browser starts a private virtual display for the browser and cleans it up on close (opt out with `AGENT_BROWSER_NO_XVFB=1`). Needed for [WebGPU screenshots](#webgpu), and useful for extensions that misbehave headless.
1156
+
1151
1157
  > **Note:** Browser extensions work in both headed and headless mode (Chrome's `--headless=new`).
1152
1158
 
1159
+ ## WebGPU
1160
+
1161
+ Headless Chrome does not expose WebGPU by default, so pages using it (three.js `WebGPURenderer`, Babylon.js, etc.) silently render black. The `--webgpu` flag enables a launch preset that makes WebGPU work, including in GPU-less containers and CI:
1162
+
1163
+ ```bash
1164
+ agent-browser --webgpu open https://my-webgpu-app.example.com
1165
+ agent-browser screenshot app.png
1166
+ ```
1167
+
1168
+ On macOS and Windows this uses the hardware Metal/D3D backend. On Linux it routes WebGPU through SwiftShader's software Vulkan (no GPU needed), which requires the system Vulkan loader and Mesa ICD:
1169
+
1170
+ ```bash
1171
+ apt-get install -y libvulkan1 mesa-vulkan-drivers
1172
+ ```
1173
+
1174
+ One upstream caveat: headless Chrome cannot capture WebGPU canvas presentation in screenshots on Windows and Linux (rendering and in-page readbacks work; the capture is black). Screenshots of WebGPU pages work headless on macOS; on Windows run `--headed` in a logged-in desktop session; on Linux just add `--headed` — when no `DISPLAY` is set and Xvfb is installed, agent-browser starts a private virtual display automatically (opt out with `AGENT_BROWSER_NO_XVFB=1`).
1175
+
1176
+ Verify the full pipeline (adapter, render pass, and screenshot capture) with:
1177
+
1178
+ ```bash
1179
+ agent-browser doctor --webgpu
1180
+ ```
1181
+
1182
+ Notes for WebGPU pages:
1183
+
1184
+ - WebGPU only exists in secure contexts (`https://`, `http://localhost`, or `file://`).
1185
+ - three.js `WebGPURenderer` initializes asynchronously and silently falls back to WebGL2 when no adapter is available — wait for the app to render its first frame before taking a screenshot.
1186
+ - To prefer a real GPU on Linux instead of SwiftShader, override both the Vulkan driver and the adapter with `--args "--use-vulkan=native,--use-webgpu-adapter=default"` (user args win over the preset; `--use-webgpu-adapter` alone still enumerates only SwiftShader).
1187
+
1188
+ See the [WebGPU docs page](https://agent-browser.dev/webgpu) for the full platform matrix and container recipe.
1189
+
1153
1190
  ## Authenticated Sessions
1154
1191
 
1155
1192
  Use `--headers` to set HTTP headers for a specific origin, enabling authentication without login flows:
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-browser",
3
- "version": "0.31.0",
3
+ "version": "0.31.2",
4
4
  "description": "Browser automation CLI for AI agents",
5
5
  "type": "module",
6
6
  "engines": {
@@ -228,7 +228,7 @@ SESSION="$(agent-browser session id --scope worktree --prefix my-app)"
228
228
  agent-browser --session "$SESSION" --restore open https://app.example.com
229
229
  ```
230
230
 
231
- `--restore` with no value uses the current `--session` as the persistence key. Agent skills should prefer this over hand-built state file paths. Use `--restore-save auto` by default so a failed restore does not overwrite the previous known-good state.
231
+ `--restore` with no value uses the current `--session` as the persistence key. Agent skills should prefer this over hand-built state file paths. Use `--restore-save auto` by default so a failed restore does not overwrite the previous known-good state. State is saved on close and also periodically while the browser is open (at most once per `AGENT_BROWSER_AUTOSAVE_INTERVAL_MS`, default 30000), so state survives even if the user closes the browser window by hand.
232
232
 
233
233
  ```bash
234
234
  agent-browser --session "$SESSION" --restore --restore-check-text Dashboard open https://app.example.com
@@ -400,6 +400,8 @@ EOF
400
400
 
401
401
  **Cross-origin iframe not accessible** Cross-origin iframes that block accessibility tree access are silently skipped. Use `frame "#iframe"` to switch into them explicitly if the parent opts in, otherwise the iframe's contents aren't available via snapshot — fall back to `eval` in the iframe's origin or use the `--headers` flag to satisfy CORS.
402
402
 
403
+ **WebGPU page renders black in screenshots** Headless Chrome doesn't expose WebGPU by default; three.js `WebGPURenderer` then silently falls back or renders nothing. Relaunch with the `--webgpu` flag, wait for the app's first rendered frame, then screenshot. On Linux install `libvulkan1 mesa-vulkan-drivers` first. If it's still black on Windows/Linux, that's an upstream headless-capture limitation: add `--headed` (needs a logged-in desktop on Windows; on Linux agent-browser starts a private virtual display automatically when Xvfb is installed — never wrap in `xvfb-run`, which kills the display when the CLI exits while the browser lives on). Verify with `agent-browser doctor --webgpu`. See [references/webgpu.md](references/webgpu.md).
404
+
403
405
  **Authentication expires mid-workflow** Use `--session <id> --restore` so your session survives browser restarts. Check `agent-browser session info --json` if restore fails. See [references/session-management.md](references/session-management.md) and [references/authentication.md](references/authentication.md).
404
406
 
405
407
  ## Global flags worth knowing
@@ -408,6 +410,7 @@ EOF
408
410
  --session <name> # isolated browser session
409
411
  --json # JSON output (for machine parsing)
410
412
  --headed # show the window (default is headless)
413
+ --webgpu # enable WebGPU (software Vulkan on Linux, no GPU needed)
411
414
  --auto-connect # connect to an already-running Chrome
412
415
  --cdp <port> # connect to a specific CDP port
413
416
  --profile <name|path> # use a Chrome profile (login state survives)
@@ -466,4 +469,5 @@ That pulls in:
466
469
  - `references/profiling.md` — Chrome DevTools tracing and profiling
467
470
  - `references/video-recording.md` — video capture options
468
471
  - `references/proxy-support.md` — proxy configuration
472
+ - `references/webgpu.md` — screenshots/video of WebGPU pages (three.js, Babylon.js), Linux/CI setup
469
473
  - `templates/*` — starter shell scripts for auth, capture, form automation
@@ -365,7 +365,8 @@ Tool calls use the same config files and environment variables as the CLI. Each
365
365
  ```bash
366
366
  agent-browser --session <name> ... # Isolated browser session
367
367
  agent-browser --json ... # JSON output for parsing
368
- agent-browser --headed ... # Show browser window (not headless)
368
+ agent-browser --headed ... # Show browser window (not headless; on displayless Linux an Xvfb display starts automatically)
369
+ agent-browser --webgpu ... # Enable WebGPU (SwiftShader software Vulkan on Linux, no GPU needed)
369
370
  agent-browser --cdp <port> ... # Connect via Chrome DevTools Protocol
370
371
  agent-browser -p <provider> ... # Browser provider or configured provider plugin
371
372
  agent-browser --proxy <url> ... # Use proxy server
@@ -449,6 +450,8 @@ AGENT_BROWSER_EXTENSIONS="/ext1,/ext2" # Comma-separated extension paths
449
450
  AGENT_BROWSER_INIT_SCRIPTS="/a.js,/b.js" # Comma-separated init script paths
450
451
  AGENT_BROWSER_ENABLE="react-devtools" # Comma-separated built-in init script features
451
452
  AGENT_BROWSER_HIDE_SCROLLBARS="false" # Keep native scrollbars visible in headless Chromium screenshots
453
+ AGENT_BROWSER_WEBGPU="1" # Enable the WebGPU launch preset (see references/webgpu.md)
454
+ AGENT_BROWSER_NO_XVFB="1" # Disable automatic Xvfb for headed mode on displayless Linux
452
455
  AGENT_BROWSER_PROVIDER="browserbase" # Browser provider or configured provider plugin
453
456
  AGENT_BROWSER_STREAM_PORT="9223" # Override WebSocket streaming port (default: OS-assigned)
454
457
  AGENT_BROWSER_CONFIG="./agent-browser.json" # Custom config file
@@ -57,7 +57,7 @@ SESSION="$(agent-browser session id --scope worktree --prefix next-dev-loop)"
57
57
  agent-browser --session "$SESSION" --restore open https://app.example.com/dashboard
58
58
  ```
59
59
 
60
- State is loaded before navigation and saved on close, daemon shutdown, idle timeout, and compatible relaunch. The default save policy is `--restore-save auto`, which skips auto-save if restore failed or validation failed.
60
+ State is loaded before navigation and saved on close, daemon shutdown, idle timeout, and compatible relaunch. It is also saved periodically while the browser is open (after commands settle, at most once per `AGENT_BROWSER_AUTOSAVE_INTERVAL_MS`, default 30000; set to `0` to save only on close), so a browser window the user closes by hand still leaves a recent save behind. Idle sessions keep saving on the same interval, capturing changes the page makes on its own such as token refreshes. The default save policy is `--restore-save auto`, which skips auto-save if restore failed or validation failed; `never` disables periodic autosave too.
61
61
 
62
62
  ```bash
63
63
  agent-browser --session "$SESSION" --restore --restore-check-url "**/dashboard" open https://app.example.com/dashboard
@@ -0,0 +1,118 @@
1
+ # WebGPU
2
+
3
+ Screenshots and video of WebGPU pages (three.js `WebGPURenderer`, Babylon.js, raw WebGPU) in headless Chrome. Without setup this is a silent failure: the page loads, the screenshot succeeds, and the canvas is black.
4
+
5
+ ## Quick start
6
+
7
+ ```bash
8
+ agent-browser --webgpu open https://my-webgpu-app.example.com
9
+ # wait for the app to render (see "Timing" below)
10
+ agent-browser screenshot app.png
11
+ ```
12
+
13
+ `--webgpu` (or `AGENT_BROWSER_WEBGPU=1`, or `"webgpu": true` in agent-browser.json) applies a launch preset:
14
+
15
+ - everywhere: `--enable-unsafe-webgpu` (WebGPU is hidden in headless/blocklisted environments by default)
16
+ - Linux only: `--enable-features=Vulkan --use-angle=vulkan --use-vulkan=swiftshader --use-webgpu-adapter=swiftshader --disable-vulkan-surface` — routes WebGPU through SwiftShader's software Vulkan, so it works with no GPU (containers, CI)
17
+
18
+ macOS uses the hardware Metal backend; Windows uses D3D. Nothing extra to install on either.
19
+
20
+ ## Platform matrix (verified)
21
+
22
+ | Platform | WebGPU rendering (headless) | Screenshots of WebGPU canvases |
23
+ |---|---|---|
24
+ | macOS | works | works headless |
25
+ | Windows | works (hardware D3D) | **headless captures black** — use `--headed` on a logged-in desktop |
26
+ | Linux | works (SwiftShader Vulkan) | headless capture not supported upstream — add `--headed` (virtual display starts automatically) |
27
+
28
+ The Windows/Linux screenshot gap is an upstream headless-Chrome limitation: WebGPU canvas *presentation* never reaches the headless compositor, even though rendering itself works (verified by pixel readback). It is not an agent-browser or flag problem — no known flag combination fixes it. Rendering, `eval`-based pixel readbacks, and compute all work headless everywhere.
29
+
30
+ On Linux, `--headed` is all you need even on displayless servers and containers: when no `DISPLAY` is set and Xvfb is installed (`apt-get install -y xvfb`), agent-browser starts a private virtual display for the browser and tears it down with it. Set `AGENT_BROWSER_NO_XVFB=1` to opt out.
31
+
32
+ ```bash
33
+ agent-browser --webgpu --headed open https://my-webgpu-app.example.com
34
+ agent-browser screenshot app.png # real WebGPU pixels, no display hardware
35
+ ```
36
+
37
+ On Windows, the session must run headed in a logged-in desktop session (an ssh/Session-0 context is not enough — schedule the launch on the interactive desktop, e.g. `schtasks /IT`, then drive it from anywhere).
38
+
39
+ ## Verify the pipeline
40
+
41
+ ```bash
42
+ agent-browser doctor --webgpu
43
+ ```
44
+
45
+ This launches a scratch session with the preset and pixel-checks two stages separately:
46
+
47
+ 1. **render** — requests an adapter (with retries; a cold Chrome returns null while the GPU process starts), clears an offscreen texture to red through a real render pass, and reads the buffer back. Proves WebGPU works at all, and reports the adapter (e.g. `nvidia ampere`, `apple metal-3`, `google swiftshader`).
48
+ 2. **screenshot** — decodes an actual screenshot of a presenting canvas. Proves the capture path. Expected to fail headless on Windows/Linux (see matrix); the failure message says so and points at `--headed`.
49
+
50
+ Add `--headed` (`agent-browser doctor --webgpu --headed`) to validate the capture path itself — on displayless Linux the probe starts its own Xvfb, so both checks should pass.
51
+
52
+ ## Linux / containers / CI
53
+
54
+ The SwiftShader Vulkan path needs the system Vulkan loader and Mesa ICD. Without them `requestAdapter()` returns null (or fails with "A valid external Instance reference no longer exists"):
55
+
56
+ ```bash
57
+ apt-get install -y libvulkan1 mesa-vulkan-drivers
58
+ ```
59
+
60
+ Container recipe (Debian/Ubuntu base; xvfb needed only for the screenshot path). Verified with both Chrome for Testing and Debian's `chromium` package (set `AGENT_BROWSER_EXECUTABLE_PATH=/usr/bin/chromium` for the latter — useful on ARM64, where Chrome for Testing has no Linux builds):
61
+
62
+ ```dockerfile
63
+ FROM node:22-bookworm-slim
64
+ RUN apt-get update && apt-get install -y \
65
+ ca-certificates libvulkan1 mesa-vulkan-drivers xvfb xauth \
66
+ && rm -rf /var/lib/apt/lists/*
67
+ RUN npm install -g agent-browser \
68
+ && agent-browser install # downloads Chrome for Testing
69
+ ```
70
+
71
+ No real GPU or `/dev/dri` is required. To prefer a real GPU on a Linux machine that has working hardware Vulkan, override both the Vulkan driver and the adapter — the preset pins `--use-vulkan=swiftshader`, so overriding only the adapter still enumerates SwiftShader (user `--args` win over the preset):
72
+
73
+ ```bash
74
+ agent-browser --webgpu --args "--use-vulkan=native,--use-webgpu-adapter=default" open ...
75
+ ```
76
+
77
+ ## Secure contexts
78
+
79
+ `navigator.gpu` only exists in secure contexts. `https://`, `http://localhost`, and `file://` qualify; a plain `http://` LAN address or `data:` URL does not — WebGPU will be `undefined` there no matter which flags are set.
80
+
81
+ ## Timing: don't screenshot too early
82
+
83
+ WebGPU apps initialize asynchronously. A screenshot taken at `load` captures a blank canvas with no error anywhere. In particular:
84
+
85
+ - **three.js `WebGPURenderer`**: `renderer.init()` is async; the first frame lands only after it resolves. Also note three.js **silently falls back to WebGL2** when it can't get a WebGPU adapter — the page "works" but you're not testing WebGPU (and on old setups the WebGL fallback itself may be black).
86
+ - Wait for an app-specific signal before capturing: a canvas with content, a "ready" DOM marker, or simply a rendered-frame check:
87
+
88
+ ```bash
89
+ agent-browser wait --fn "window.__appReady === true"
90
+ # or generically: give the render loop a frame or two
91
+ agent-browser eval "new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)))"
92
+ agent-browser screenshot app.png
93
+ ```
94
+
95
+ To check which backend a three.js app actually got:
96
+
97
+ ```bash
98
+ agent-browser eval "document.querySelector('canvas').getContext('webgpu') ? 'webgpu' : 'webgl-fallback'"
99
+ ```
100
+
101
+ ## Reading pixels back inside the page
102
+
103
+ If you `eval` your own WebGPU readback, don't snapshot the canvas (`drawImage(webgpuCanvas, ...)`) — it depends on presentation timing and reads transparent black on Windows even when rendering works. Render to an offscreen texture and read it back deterministically:
104
+
105
+ ```js
106
+ const tex = device.createTexture({ size: [w, h], format: 'rgba8unorm',
107
+ usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC });
108
+ // ...render to tex, then:
109
+ encoder.copyTextureToBuffer({ texture: tex }, { buffer, bytesPerRow }, [w, h]);
110
+ device.queue.submit([encoder.finish()]);
111
+ await buffer.mapAsync(GPUMapMode.READ);
112
+ ```
113
+
114
+ This works headless on every platform (it's how `doctor --webgpu` proves rendering).
115
+
116
+ ## Performance expectations
117
+
118
+ SwiftShader is a CPU rasterizer. Simple scenes render fine; heavy three.js scenes are single-digit FPS. For screenshots that's usually irrelevant; for smooth video capture of complex scenes, use hardware (macOS/Windows, or Linux with `--use-vulkan=native,--use-webgpu-adapter=default` and real Vulkan drivers).