@parcha/pi-browser 0.1.0-beta.30 → 0.1.0-beta.301
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/CHANGELOG.md +239 -0
- package/NOTICE +39 -4
- package/README.md +125 -236
- package/dist/core/contract.d.ts +17 -5
- package/dist/core/contract.js +36 -33
- package/dist/core/custody.d.ts +19 -2
- package/dist/core/custody.js +28 -6
- package/dist/core/downloads.d.ts +44 -3
- package/dist/core/downloads.js +94 -58
- package/dist/core/driving-guard.d.ts +20 -0
- package/dist/core/driving-guard.js +190 -23
- package/dist/core/driving.d.ts +56 -2
- package/dist/core/driving.js +189 -10
- package/dist/core/effects.d.ts +80 -6
- package/dist/core/effects.js +374 -41
- package/dist/core/evidence.d.ts +1 -1
- package/dist/core/failures.d.ts +15 -1
- package/dist/core/failures.js +7 -0
- package/dist/core/files.d.ts +20 -2
- package/dist/core/files.js +161 -10
- package/dist/core/host.d.ts +29 -77
- package/dist/core/images.d.ts +32 -4
- package/dist/core/images.js +81 -16
- package/dist/core/lease.d.ts +2 -1
- package/dist/core/page-scan.d.ts +81 -2
- package/dist/core/page-scan.js +487 -13
- package/dist/core/public-fetch.d.ts +70 -9
- package/dist/core/public-fetch.js +348 -51
- package/dist/core/read-page-worker.js +5 -4
- package/dist/core/read-page.d.ts +23 -8
- package/dist/core/read-page.js +64 -20
- package/dist/core/redact.d.ts +0 -2
- package/dist/core/redact.js +0 -32
- package/dist/core/session-control.d.ts +0 -2
- package/dist/core/session-control.js +0 -5
- package/dist/core/tools.d.ts +46 -1
- package/dist/core/tools.js +88 -12
- package/dist/core/usage.d.ts +4 -3
- package/dist/core/usage.js +5 -4
- package/dist/core/vault.d.ts +0 -10
- package/dist/core/vault.js +0 -13
- package/dist/core/web.d.ts +2 -111
- package/dist/core/web.js +0 -443
- package/dist/driver/cdp.d.ts +6 -0
- package/dist/driver/cdp.js +245 -0
- package/dist/driver/page-driver.js +110 -7
- package/dist/driver/sealed.d.ts +4 -12
- package/dist/driver/sealed.js +23 -37
- package/dist/driver/stagehand.d.ts +12 -15
- package/dist/driver/stagehand.js +21 -17
- package/dist/durable/result.d.ts +1 -2
- package/dist/durable/result.js +2 -2
- package/dist/durable/store.d.ts +17 -3
- package/dist/durable/store.js +231 -64
- package/dist/durable.d.ts +50 -17
- package/dist/durable.js +107 -106
- package/dist/index.d.ts +3 -3
- package/dist/index.js +5 -3
- package/dist/live-view/index.d.ts +4 -1
- package/dist/live-view/index.js +5 -0
- package/dist/live-view/protocol.d.ts +39 -7
- package/dist/live-view/protocol.js +2 -0
- package/dist/live-view/provider.d.ts +2 -2
- package/dist/live-view/provider.js +2 -2
- package/dist/live-view/server.d.ts +55 -2
- package/dist/live-view/server.js +282 -35
- package/dist/live-view/stream.js +16 -3
- package/dist/live-view/viewer.js +106 -13
- package/dist/providers/cdp.d.ts +0 -1
- package/dist/providers/cdp.js +35 -13
- package/dist/providers/chrome-args.d.ts +3 -0
- package/dist/providers/chrome-args.js +13 -2
- package/dist/providers/profiles.d.ts +1 -15
- package/dist/providers/profiles.js +1 -64
- package/dist/providers/shared.d.ts +1 -47
- package/dist/providers/shared.js +1 -82
- package/dist/providers/worker-extension.d.ts +20 -1
- package/dist/providers/worker-extension.js +86 -7
- package/dist/testing/backend.d.ts +6 -24
- package/dist/testing/backend.js +7 -30
- package/dist/vault-session.d.ts +4 -7
- package/dist/vault-session.js +26 -81
- package/dist/vendor/browser-use-pi/ax.d.ts +106 -0
- package/dist/vendor/browser-use-pi/ax.js +642 -0
- package/dist/vendor/browser-use-pi/cdp.d.ts +19 -0
- package/dist/vendor/browser-use-pi/cdp.js +106 -0
- package/dist/vendor/browser-use-pi/page.d.ts +29 -0
- package/dist/vendor/browser-use-pi/page.js +99 -0
- package/package.json +15 -46
- package/src/vendor/browser-use-pi/UPSTREAM.json +25 -0
- package/src/vendor/stagehand-facade/UPSTREAM.json +0 -4
- package/dist/coding-agent-local.d.ts +0 -12
- package/dist/coding-agent-local.js +0 -72
- package/dist/coding-agent.d.ts +0 -134
- package/dist/coding-agent.js +0 -640
- package/dist/core/sites.d.ts +0 -33
- package/dist/core/sites.js +0 -104
- package/dist/driver/extension-worker.d.ts +0 -9
- package/dist/driver/extension-worker.js +0 -185
- package/dist/durable/web.d.ts +0 -47
- package/dist/durable/web.js +0 -41
- package/dist/providers/assigned.d.ts +0 -18
- package/dist/providers/assigned.js +0 -75
- package/dist/providers/browserbase-net.d.ts +0 -12
- package/dist/providers/browserbase-net.js +0 -95
- package/dist/providers/browserbase.d.ts +0 -169
- package/dist/providers/browserbase.js +0 -319
- package/dist/providers/kernel.d.ts +0 -58
- package/dist/providers/kernel.js +0 -291
- package/dist/recorder/credential.d.ts +0 -9
- package/dist/recorder/credential.js +0 -49
- package/dist/recorder/follow.d.ts +0 -36
- package/dist/recorder/follow.js +0 -163
- package/dist/recorder/frames.d.ts +0 -87
- package/dist/recorder/frames.js +0 -377
- package/dist/recorder/index.d.ts +0 -4
- package/dist/recorder/index.js +0 -7
- package/dist/recorder/jpeg.d.ts +0 -8
- package/dist/recorder/jpeg.js +0 -70
- package/dist/recorder/track.d.ts +0 -107
- package/dist/recorder/track.js +0 -280
- package/dist/vendor/stagehand-facade/screenshot-transport.d.ts +0 -15
- package/dist/vendor/stagehand-facade/screenshot-transport.js +0 -51
- /package/dist/{providers → core}/cdp-call.d.ts +0 -0
- /package/dist/{providers → core}/cdp-call.js +0 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Your agent gets its own browser, and you can take over and hand it back.
|
|
4
4
|
|
|
5
|
-
- **Its own browser.** The agent drives a Chrome of its own: a local Chrome, Browserbase
|
|
5
|
+
- **Its own browser.** The agent drives a Chrome of its own: a local Chrome, or a hosted browser its host provides (agentrun-serve's Browserbase and Kernel, through its computer providers). It reads pages, clicks, types and takes screenshots. A local Chrome needs no key.
|
|
6
6
|
- **You can take over and hand it back.** A host mounts the live view in a few lines, and then a person sees the agent's page, uses the mouse and keys, and lets the agent go on. While the person is driving, the agent's browser calls are refused. The agent can also ask a person for a step only a person can do, and wait for the answer. See [Take over and hand back](#take-over-and-hand-back). For now, use the live view with test accounts on practice sites only: the model's own page code can read what a person types there.
|
|
7
7
|
- **Credentials you register stay out of what the model sees.** Credentials you register, and keys of the common shapes, are replaced with `[redacted]` in every tool result, failure, filed page and log. See [Credentials](#credentials).
|
|
8
8
|
- **Every page the agent reads is filed as evidence.** The file holds the page's URL, its title and its SHA-256.
|
|
@@ -10,20 +10,17 @@ Your agent gets its own browser, and you can take over and hand it back.
|
|
|
10
10
|
|
|
11
11
|
If the process dies, a pi-durable host recovers the session and does not repeat an action. See [For hosts](#for-hosts).
|
|
12
12
|
|
|
13
|
-
Part of [AgentRun](https://github.com/Parcha-ai/agentrun). Node `>=22.
|
|
14
|
-
pi-durable and chord peers
|
|
13
|
+
Part of [AgentRun](https://github.com/Parcha-ai/agentrun). Node `>=24.22.3`, pi 1.5.2 exactly (its
|
|
14
|
+
pi-durable and chord peers). ESM only: the
|
|
15
15
|
package has `import` entries and no `require` entry.
|
|
16
16
|
|
|
17
17
|
## Install
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
|
-
pi install npm:@parcha/pi-browser@latest # the pi coding agent's extension
|
|
21
20
|
npm install @parcha/pi-browser@latest # the library: providers, driver, durable adapter
|
|
22
|
-
npm install @parcha/pi-browser@latest @earendil-works/pi-durable@1.
|
|
21
|
+
npm install @parcha/pi-browser@latest @earendil-works/pi-durable@1.5.2 @earendil-works/chord@1.5.2 @earendil-works/pi-ai@1.5.2 # a pi-durable host: its peers, pinned to 1.5.2
|
|
23
22
|
```
|
|
24
23
|
|
|
25
|
-
`pi install` loads the extension. A Chrome starts on the model's first browser call, and not before. pi 1.4 is not supported yet; a later release widens the range.
|
|
26
|
-
|
|
27
24
|
## Quick start
|
|
28
25
|
|
|
29
26
|
A local Chrome, one page, one snapshot. It needs Chrome or Chromium; `CHROME_PATH` names it. As root or in a container, Chrome cannot start its sandbox: set `PI_BROWSER_NO_SANDBOX=1`, or pass `sandbox: false` beside `executablePath`, and run the container with `--init`, or a Chrome killed on cleanup stays a zombie.
|
|
@@ -70,7 +67,7 @@ await backend.provider.release(session);
|
|
|
70
67
|
EOF
|
|
71
68
|
```
|
|
72
69
|
|
|
73
|
-
It prints the page's accessibility tree, the same text `snapshot` gives a model:
|
|
70
|
+
It prints the page's accessibility tree, the same text that `snapshot` gives a model:
|
|
74
71
|
|
|
75
72
|
```
|
|
76
73
|
[0] main
|
|
@@ -79,24 +76,23 @@ It prints the page's accessibility tree, the same text `snapshot` gives a model:
|
|
|
79
76
|
|
|
80
77
|
## Demos
|
|
81
78
|
|
|
82
|
-
|
|
79
|
+
Two runnable demos live in `examples/` in the repository. They are not in the npm package. Build once with `pnpm install --frozen-lockfile && pnpm run build`, then run one from the repository root. Each needs Chrome or Chromium (`CHROME_PATH` names it) except where it says otherwise.
|
|
83
80
|
|
|
84
81
|
| Demo | Run | What it shows |
|
|
85
82
|
|---|---|---|
|
|
86
|
-
| [`examples/one-script-three-providers.mjs`](examples/one-script-three-providers.mjs) | `node packages/pi-browser/examples/one-script-three-providers.mjs https://example.com` | The same script on a local Chrome, Browserbase or Kernel. `PI_BROWSER_PROVIDER=browserbase` needs `BROWSERBASE_API_KEY` and the Browserbase SDK; `kernel` needs `KERNEL_API_KEY`. The tests run the local Chrome path only. |
|
|
87
83
|
| [`examples/hold-an-irreversible-action.mjs`](examples/hold-an-irreversible-action.mjs) | `node packages/pi-browser/examples/hold-an-irreversible-action.mjs` | Under the `ask` policy a form post is held until a person approves it. The demo refuses, and the local server it posts to counts zero requests. |
|
|
88
84
|
| [`examples/crash-and-resume.mjs`](examples/crash-and-resume.mjs) | `node packages/pi-browser/examples/crash-and-resume.mjs`, twice | The first run sets a page title and kills itself with SIGKILL between two tool calls. The second recovers the same Chrome from the run's own store and reads the title back. A scripted model stands in for a real one. It uses the pi-durable packages the repository already installs. Delete `$TMPDIR/pi-browser-crash-demo` to start over. |
|
|
89
|
-
| [`examples/read-a-pdf.mjs`](examples/read-a-pdf.mjs) | `node packages/pi-browser/examples/read-a-pdf.mjs` | `web_fetch` on a PDF the fetch service cannot convert. It fetches the file raw and hands the bytes to your extractor, here poppler's `pdftotext` (needs poppler installed). The fetch service is a stand-in that answers HTTP 400 for a PDF, as Browserbase does. It does not need Chrome. |
|
|
90
85
|
|
|
91
86
|
## Providers
|
|
92
87
|
|
|
93
|
-
The same tools run on
|
|
88
|
+
The same tools run on any browser a `BrowserProvider` gives. The package carries the local one; a hosted browser is the
|
|
89
|
+
host's, through a provider of its own (agentrun-serve drives Browserbase and Kernel through its computer providers, so the
|
|
90
|
+
package names no vendor).
|
|
94
91
|
|
|
95
92
|
| Provider | What it is | What it needs |
|
|
96
93
|
|---|---|---|
|
|
97
|
-
| Local Chrome (`/providers/cdp`) | A Chrome the package starts and stops by exact pid, with its own profile directory and a free debugging port. It can also attach to a Chrome you already run, at a CDP endpoint. | Chrome or Chromium. No key. |
|
|
98
|
-
|
|
|
99
|
-
| Kernel (`/providers/kernel`) | A Kernel browser, through its REST API. | `KERNEL_API_KEY`. No SDK. |
|
|
94
|
+
| Local Chrome (`/providers/cdp`) | A Chrome the package starts and stops by exact pid, with its own profile directory and a free debugging port. It can also attach to a Chrome you already run, at a CDP endpoint. | Chrome or Chromium 137 or later. No key. |
|
|
95
|
+
| A host's own (`BrowserProvider`, `core/host.ts`) | Any browser that answers CDP: the host makes, finds and releases its sessions and hands over a CDP URL. | Whatever the host's vendor needs. |
|
|
100
96
|
|
|
101
97
|
The local Chrome's options, in `cdpProvider({ chrome: { ... } })`:
|
|
102
98
|
|
|
@@ -107,7 +103,7 @@ The local Chrome's options, in `cdpProvider({ chrome: { ... } })`:
|
|
|
107
103
|
| `args` | Extra Chrome flags, added after the package's own. |
|
|
108
104
|
| `sandbox` | Chrome's own sandbox, on unless `false`. When absent, `PI_BROWSER_NO_SANDBOX=1` turns it off. Turn it off only where Chrome cannot start its sandbox (root, a container, restricted user namespaces), and only for pages you trust. A Chrome that exits before it opens its debugging port fails the create with its last lines of stderr, and with this hint when it aborted or named the sandbox. |
|
|
109
105
|
|
|
110
|
-
|
|
106
|
+
A host passes the provider it wants; see [For hosts](#for-hosts).
|
|
111
107
|
|
|
112
108
|
## Take over and hand back
|
|
113
109
|
|
|
@@ -119,15 +115,11 @@ A person and the agent never drive the browser together. There are two ways for
|
|
|
119
115
|
|
|
120
116
|
**The limit.** The credential guards are not in this release. Until they ship, use the live view with test accounts on practice sites only. The model's own page code can read what a person types there.
|
|
121
117
|
|
|
122
|
-
What
|
|
123
|
-
|
|
124
|
-
| | The pi extension, as `pi install` loads it | A host that wires it |
|
|
125
|
-
|---|---|---|
|
|
126
|
-
| Live view of a local Chrome | not wired | `createLiveView` and `liveViewProvider` |
|
|
127
|
-
| Live-view URL of a Browserbase or Kernel session | not shown to anyone | handed to the host only, through `onSession` or the handoff port |
|
|
128
|
-
| `browser_request_handoff` | not listed | listed when the host passes a `handoff` port |
|
|
118
|
+
What a host wires:
|
|
129
119
|
|
|
130
|
-
The
|
|
120
|
+
- **The live view of a local Chrome:** `createLiveView` and `liveViewProvider`.
|
|
121
|
+
- **The live-view URL of a Browserbase or Kernel session:** handed to the host only, through `onSession` or the handoff port.
|
|
122
|
+
- **`browser_request_handoff`:** listed when the host passes a `handoff` port.
|
|
131
123
|
|
|
132
124
|
### The live view of your own Chrome
|
|
133
125
|
|
|
@@ -144,7 +136,7 @@ const liveView = createLiveView({
|
|
|
144
136
|
server.on("request", (req, res) => { if (!liveView.handle(req, res)) next(req, res); });
|
|
145
137
|
server.on("upgrade", (req, socket, head) => { if (!liveView.upgrade(req, socket, head)) socket.destroy(); });
|
|
146
138
|
|
|
147
|
-
const provider = liveViewProvider(cdpProvider({ chrome }), liveView);
|
|
139
|
+
const provider = liveViewProvider(cdpProvider({ chrome }), liveView);
|
|
148
140
|
createBrowserExtension({ provider: () => provider, onSession: (row) => { /* row.liveView.fullscreen is the viewer's URL */ }, ... });
|
|
149
141
|
```
|
|
150
142
|
|
|
@@ -153,13 +145,41 @@ token is 256 random bits in the fragment, so it reaches no server log, proxy or
|
|
|
153
145
|
nothing is accepted before it. The upgrade's `Origin` must be the viewer's own origin (behind a proxy, pass the upgrade through with `Origin` intact).
|
|
154
146
|
There is one authenticated viewer per session (a second is refused `viewer_in_use`); the token, the stream and the viewer's socket end at the session's release.
|
|
155
147
|
The page is served with `Referrer-Policy: no-referrer`, `default-src 'self'` and `frame-ancestors` set to `hostOrigin`. The viewer may send a page only to
|
|
156
|
-
http(s) addresses. Frames are held one at a time and acknowledged after they were sent;
|
|
148
|
+
http(s) addresses. Frames are held one at a time and acknowledged after they were sent; the live view writes none anywhere. A host may watch a
|
|
149
|
+
session's frames itself, with or without a viewer (`liveView.watch(tag, { frame, ended })`, which AgentRun's run video records): the viewer and the
|
|
150
|
+
watchers share the session's one screencast.
|
|
157
151
|
|
|
158
152
|
Every browser tool is a model call on its session's gate (`drivingGates`, shared by default between the live view and the toolset, so you pass nothing). To use your own
|
|
159
153
|
registry, pass the same one to both sides: `const gates = createDrivingGates({ idleMs: 5_000 }); createLiveView({ hostOrigin, gates }); createBrowserExtension({ ..., gates });`.
|
|
160
154
|
|
|
161
155
|
`drivingGates(tag).viewing()` is true for as long as an authenticated viewer is connected to that session, even when the person sits still longer than the 3 s driving window (a person mid-sign-in): the host's own custody reads it before it releases a session on its own. A custom registry's gates implement `viewing()` and `setViewing(on)`; the live view sets it on a viewer's hello and clears it when that viewer leaves or the session is released.
|
|
162
156
|
|
|
157
|
+
`readOnly: true` makes the view watch-only: every input, navigation and dialog answer a viewer sends is dropped on the server, before the browser (`held read_only`, and
|
|
158
|
+
one that keeps sending is closed), its `ready` carries `readOnly: true` and the page shows "view only" with its controls off; a watching viewer never sets `viewing`, so it
|
|
159
|
+
keeps no session open. A browser with no page to show (a headless one that starts with none, or whose last page closed) sends `no_page`, and the page says "No page yet"
|
|
160
|
+
until one opens.
|
|
161
|
+
|
|
162
|
+
`takeOver: { take(tag) }` makes the view drive only once the person takes the browser. The page shows **Take over** and **Hand back** in its own bar and sends `take`
|
|
163
|
+
and `give`; outside a hold every input, navigation and dialog answer is dropped on the server (`held not_taken`). A `take` asks the host's `take(tag)` first, which may
|
|
164
|
+
refuse in its own words (a spend cap with no room for the person's time; the viewer shows `take_refused` with them), or answers `{ end(why), started?(), cancel?() }` (`started` as the hold goes live, `cancel` instead of `end` when no hold starts after all: the session released, the viewer gone, or the browser held already, which the viewer is told as `take_refused`); the session's gate then
|
|
165
|
+
holds the browser for the person (`drivingGates(tag).take()`) until their `give`, `holdIdleMs` with no input (15 minutes), `holdAwayMs` with no viewer connected
|
|
166
|
+
(2 minutes), or the session's release, and `end` is called once with why (`given`, `answered`, `cap`, `idle`, `away`, `released`). A host gives the
|
|
167
|
+
browser back at its spend cap with `drivingGates(tag).give("cap", words)`: the viewer's `hold` end carries the words as `message`. The viewer is told `hold` as it starts
|
|
168
|
+
and ends; `ready` carries `takeOver: true` and whether it holds now, so a viewer that reconnects within the away window still holds it. While held, every model call
|
|
169
|
+
waits inside its tool (it does not fail; an abort ends the wait with nothing done), and past the hold's end until the person's last command has returned (a Back
|
|
170
|
+
between reading the history and moving; at most `settleMs`, 10 s, after which that command is let go and moves nothing more), then goes on with its old element ids dropped and told plainly that the person had
|
|
171
|
+
the browser and the page may have changed. Its result's `details` then say how long it waited (`waited_for_person_ms`), so a timeline shows the call waited for the
|
|
172
|
+
person rather than acting while they had the browser; a call stopped while it waits did nothing and carries none. Each change of hands moves the gate's epoch (`drivingGates(tag).epoch()`), and a driver a call took before it is refused at
|
|
173
|
+
its next act (a `FenceRefusal`), so an agent action from before the person took over never reaches the page: a `run` of
|
|
174
|
+
several actions has all of them checked against the snapshot first (`checkActions`: a stale id anywhere sends none), then is
|
|
175
|
+
sent one action at a time, each checked against the epoch. One stopped partway (a take, or a later action failing) says
|
|
176
|
+
`effect: "partial"` with `completed`, how many ran. An act already sent (a `run`'s code is one batch inside
|
|
177
|
+
the browser, out of reach once sent) ends first: a take while a model call runs is held at once, no call starts, and the
|
|
178
|
+
hold goes live (`holding()`, the viewer's `hold`, the person's input taken) once that call returns. A host gives the browser back itself with
|
|
179
|
+
`drivingGates(tag).give("answered")` (an agent's handoff that was answered). A watching take-over viewer keeps no session from its idle release; a held one is kept by
|
|
180
|
+
its hold. `viewerAssets` (from `@parcha/pi-browser/live-view`) are the viewer's page, script and style, for a host that serves the page from its own origin and
|
|
181
|
+
passes only the WebSocket to the live view.
|
|
182
|
+
|
|
163
183
|
Limits: JS dialogs show with accept and dismiss. A file chooser and downloads are not supported.
|
|
164
184
|
|
|
165
185
|
## Saved sign-ins
|
|
@@ -169,12 +189,11 @@ This section says where a profile's state lives. A host can ask for a browser pr
|
|
|
169
189
|
Where the profile lives:
|
|
170
190
|
|
|
171
191
|
- **Local Chrome:** a directory `.profiles/<name>` under the profile root you give the provider. A session that saves runs on that directory. A session that does not save runs on a copy, and the profile stays as it was.
|
|
172
|
-
- **
|
|
173
|
-
- **Kernel:** a Kernel profile of that name, created if it is not there.
|
|
192
|
+
- **A host's provider:** wherever its vendor keeps one (agentrun-serve opens a vendor's saved profile by the pointer it holds for the run's sign-in).
|
|
174
193
|
|
|
175
|
-
It is never your own browser's profile.
|
|
194
|
+
It is never your own browser's profile.
|
|
176
195
|
|
|
177
|
-
One session at a time may save to a profile in one process. A second saver is refused, and the message says why. Across processes, the last session to end wins.
|
|
196
|
+
One session at a time may save to a profile in one process. A second saver is refused, and the message says why. Across processes, the last session to end wins.
|
|
178
197
|
|
|
179
198
|
|
|
180
199
|
## The tools
|
|
@@ -183,26 +202,13 @@ One session at a time may save to a profile in one process. A second saver is re
|
|
|
183
202
|
|---|---|---|
|
|
184
203
|
| `snapshot` | The page's accessibility tree with bracketed ids: a working view for the next `run`. Never filed, so it is not citable evidence. | Reruns. |
|
|
185
204
|
| `screenshot`, `browser_read` | Read the page. Each read is filed as evidence with its URL, SHA-256 and the offset into the session's recording. A screenshot is held to 2,000 px on its long edge. A `screenshot` can take a `clip` (CSS pixels from the viewport's top-left corner), an `id` from the latest snapshot or a CSS `selector` (scrolled into view first) to capture one region (a blank `id` or `selector`, or a clip of zero width and height, counts as not given); an empty or off-screen region, or an element that matches nothing or more than one, is refused with the typed envelope before any capture. Its `details.media` gives the image's path, type, size and the region. | Reruns. A read whose session was lost answers `session_replaced`. |
|
|
186
|
-
| `browser_downloads` | Copy what the session downloaded into the host's workspace, with a manifest of SHA-256 sums. The
|
|
187
|
-
| `run` | Act: code, or a batch of ref actions. | Never reruns. The model is told the call may have taken effect and where the page was, and the identical code is refused once (`effect_unknown`). |
|
|
205
|
+
| `browser_downloads` | Copy what the session downloaded into the host's workspace, with a manifest of SHA-256 sums. The durable adapter lists it only when the host supplies `workspace`. | Reruns; files already there are skipped. |
|
|
206
|
+
| `run` | Act: code, or a batch of ref actions (`goto` takes a URL instead of an id). An AgentRun browser computer (raw CDP) takes actions only. | Never reruns. The model is told the call may have taken effect and where the page was, and the identical code is refused once (`effect_unknown`). |
|
|
188
207
|
| `browser_release`, `browser_relaunch` | End the session; end it and open another. | Idempotent. A create carries a tag, so a rerun finds its session. |
|
|
189
208
|
| `browser_request_handoff` | Hand the session to a person for a step only a human can do, and wait for the host's handoff port to say how it ended. While the person has it, every other call answers `waiting_for_human`. Listed only when the host gives a `handoff` port. | Reruns and waits on the same request; a request asked again carries the same `request_id`, which the port treats as one. |
|
|
190
|
-
| `
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
`web_search` hits carry a `snippet` when the search has one: an excerpt of the page with its markdown links reduced to
|
|
195
|
-
their text, whitespace collapsed and clipped to `WEB_SEARCH_SNIPPET_MAX` (500) characters, redacted with the rest of the
|
|
196
|
-
answer. A host's `searchSources` (`createWebExtension`) are tried in order before the provider's own search; one that
|
|
197
|
-
throws hands the call to the next, a cancelled call is never handed on, and the answer names the source in `via`. A
|
|
198
|
-
source's optional `available()` is asked at each call; one that answers false is skipped without counting as a failure.
|
|
199
|
-
`fetchSources` (`FetchSource`) are readers tried the same way before the provider's own fetch, for a markdown read: a
|
|
200
|
-
page one answers is filed exactly as the provider's is, under `via: <name>_fetch`, and a reader's failure never becomes
|
|
201
|
-
the call's own while the provider can still be tried.
|
|
202
|
-
|
|
203
|
-
`web_fetch` and `web_search` results carry their price as pi usage (the Browserbase provider's list prices; a search
|
|
204
|
-
source's answer at the usage it reports, else the list search price). Session
|
|
205
|
-
minutes are charged by the session meter (`core/usage.ts`, wired into custody): every session tool's result carries the
|
|
209
|
+
| `browser_upload` | Choose one workspace file in a file input on the page, as a person picking it would. Nothing is submitted; `run` submits the form afterwards. The durable adapter lists it only when the host supplies `files`. | Never reruns. An upload the page does not answer fails at 60 s as possibly applied, and the identical retry is refused until the agent has looked at the page. |
|
|
210
|
+
|
|
211
|
+
Session minutes are charged by the session meter (`core/usage.ts`, wired into custody): every session tool's result carries the
|
|
206
212
|
time since the last charge, and each released session's record carries its total. A host that books session time as spend
|
|
207
213
|
passes `onCharge` (below), which hears each charge in the commit that bills it.
|
|
208
214
|
|
|
@@ -229,7 +235,7 @@ Every failure is one envelope: `ok: false`, a `code`, `retryable`, `effect` (`no
|
|
|
229
235
|
| `rate_limited` | The site or the provider answered 429. |
|
|
230
236
|
| `waiting_for_human` | A person has the browser. |
|
|
231
237
|
|
|
232
|
-
**Walls.** Naming a wall takes a judge. A host passes `decisions.classifyPage`, which gets the page's URL, status, content type and text, and answers one of eight classes: `captcha_or_bot_check`, `login_wall`, `paywall`, `region_or_geo_block`, `consent_interstitial`, `error_or_not_found`, `loading_or_js_required` or `empty_or_template`. A bot check or a region block files as `blocked`, and the others as `not_content`, each with a next step. With no judge, no page is classified. A fetch the site refuses with 401, 403, 451 or 999 still answers `blocked`.
|
|
238
|
+
**Walls.** Naming a wall takes a judge. A host passes `decisions.classifyPage`, which gets the page's URL, status, content type and text, and answers one of eight classes: `captcha_or_bot_check`, `login_wall`, `paywall`, `region_or_geo_block`, `consent_interstitial`, `error_or_not_found`, `loading_or_js_required` or `empty_or_template`. A bot check or a region block files as `blocked`, and the others as `not_content`, each with a next step. With no judge, no page is classified. A fetch the site refuses with 401, 403, 451 or 999 still answers `blocked`.
|
|
233
239
|
|
|
234
240
|
A host with a typed-question judge (Jev's `createJevRunner`, or the DSL's `runJudge`) builds the method with `createPageClassifier({ judge, budget?, maxPages?, redact? })`. `judge` is read on each page and must return a `PageJudge`; the page takes one request, which asks for its wall and for the probability that it carries instructions addressed to an AI reader. Its `injection` decision is marked at `INJECTION_THRESHOLD`. A side counts at `PAGE_WALL_THRESHOLD` (0.6). The run's page budget (`pageBudget`, `PAGE_GUARD_MAX_PAGES` pages by default) bounds how many pages are judged. An aborted page, a spent budget, and a judge that throws or answers in the wrong shape (a probability outside 0 to 1 included) each leave the page `unjudged` with no score. An answer where neither side reaches 0.6 leaves it `unjudged` and keeps its injection score: a page at or over `INJECTION_THRESHOLD` is withheld from a search's snippets and marked as an injection on a read, whatever its wall. Each records the reason in its `guard` record. The method never rejects.
|
|
235
241
|
|
|
@@ -242,7 +248,6 @@ What the package does with the credentials you register and the keys it recognis
|
|
|
242
248
|
- **Page URLs.** Every query value is replaced (the names stay), and the fragment and the userinfo are dropped, before a URL is shown or filed.
|
|
243
249
|
- **Where it runs.** The redactor runs over tool results, failure messages and details, the repeat guard's text, download reasons and the inputs to a page judge. It runs before any text is cut, filed or shown.
|
|
244
250
|
- **The live view's address** is a full-control credential. It goes to the host's `onSession` and the handoff port, and nowhere else.
|
|
245
|
-
- **Recordings.** The frame recorder keeps no frame while a password, a one-time-code field or a field it cannot read is on the page.
|
|
246
251
|
- **Browserbase.** The provider dials Browserbase through a bound credential proxy, not the raw connect URL.
|
|
247
252
|
- **Tested.** The wire tests (`test/wire/`) plant sentinel credentials in a fake provider and scan every byte a run produced: the run's entries and database, every request to the model, its reports, its evidence files and its process log. They look for each value raw, URL-encoded, hex- and base64-encoded, and for its head and tail.
|
|
248
253
|
|
|
@@ -250,115 +255,66 @@ What this does not cover: a value nobody registered and no shape matches, and wh
|
|
|
250
255
|
|
|
251
256
|
## Peers
|
|
252
257
|
|
|
253
|
-
Stagehand, undici, zod and the two HTML packages are dependencies.
|
|
258
|
+
Stagehand, undici, zod and the two HTML packages are dependencies. Three optional peers cover the rest. Install only the ones you use:
|
|
254
259
|
|
|
255
260
|
| Peer | Needed for |
|
|
256
261
|
|---|---|
|
|
257
|
-
| `@earendil-works/pi-coding-agent` | `/coding-agent`. `pi install` supplies it. |
|
|
258
262
|
| `@earendil-works/pi-durable` and `@earendil-works/chord` | `/durable`, the adapter for a pi-durable Harness. |
|
|
259
|
-
| `@browserbasehq/sdk` | the Browserbase provider. Kernel needs no SDK. |
|
|
260
|
-
|
|
261
|
-
The pi peers are `@earendil-works/pi-durable` and `chord` `>=1.1.0 <1.4.0`, and `@earendil-works/pi-coding-agent` at any version, as pi's package guidance asks of the packages it supplies. The suite passes on pi 1.1, 1.2 and 1.3, and the coding-agent entry's tests also pass on a pi 1.0.4 family.
|
|
262
263
|
|
|
263
|
-
pi
|
|
264
|
+
The pi peers are `@earendil-works/pi-durable` and `chord` `1.5.2` exactly. CI tests pi 1.5.2.
|
|
264
265
|
|
|
265
266
|
## Entries
|
|
266
267
|
|
|
267
268
|
- `@parcha/pi-browser`: the host-neutral core. The model contract (tool names, descriptions, JSON schemas, effect and
|
|
268
269
|
replay classes, the `browser` and `web` prompt sections), the typed failure envelope, the redactor, the screenshot
|
|
269
270
|
budget, the repeat guard, evidence and decision-hook types, usage and prices, `find` (chunking and ranking a long page),
|
|
270
|
-
`browser_downloads`, the opt-in request observer, and the provider interface. The public-host guard
|
|
271
|
-
|
|
272
|
-
|
|
271
|
+
`browser_downloads`, the opt-in request observer, and the provider interface. The public-host guard is here too: `publicFetch(url, { lookup?, fetchImpl?, signal?, maxBytes?, cut?, beforeRedirect? })` (a text body over `maxBytes` refused, or with `cut` answered as its first `maxBytes`, `cut: true`, the rest never read; `beforeRedirect(url)` asked with each redirect's target once its checks pass, before it is dialled, what it throws ending the fetch there), its bytes
|
|
272
|
+
variant `publicDownload(url, { lookup?, fetchImpl?, signal?, maxBytes?, beforeRedirect? })` (one file of any type, `{ url, status,
|
|
273
|
+
contentType, bytes }`, `bytes` null for a status that is not 2xx; the same hops, checks and pinned dial as
|
|
274
|
+
`publicFetch`, a declared length over `maxBytes` refused before the body is read and a body over it refused as it is
|
|
275
|
+
read), its write `publicUpload(url, bytes, { lookup?, fetchImpl?, signal?, contentType?, userAgent? })` (one PUT of
|
|
276
|
+
`bytes`, `{ url, status }`, the answer's body unread; https only and no redirect followed, so the bytes go to the URL
|
|
277
|
+
given or nowhere, with `publicFetch`'s other checks and pinned dial), and `readPage(html, url, { deadlineMs?, heapMb?, signal? })`, with `isPrivateAddress` (which also counts the ranges in `CLUSTER_INTERNAL_CIDRS` as private, GKE's Service range
|
|
278
|
+
`34.118.224.0/20` when it is unset or blank) and `pinnedLookup`. `readPage` never holds
|
|
273
279
|
the event loop: it drops a page's script, style, svg, noscript and template blocks, cuts what is left at
|
|
274
280
|
`READ_MAX_CHARS` (`truncated`, with the page's length in `html_chars`), and converts it to markdown in a worker thread
|
|
275
|
-
within `READ_DEADLINE_MS`, falling back to the page's plain text (`converted: "text"`).
|
|
281
|
+
within `READ_DEADLINE_MS`, falling back to the page's plain text (`converted: "text"`). A worker that runs out of its
|
|
282
|
+
heap (`heapMb`, default `READ_WORKER_HEAP_MB`) is not followed by that fallback: the read rejects with
|
|
283
|
+
`PageReadOutOfMemory`. Its links stop at `READ_LINKS_MAX`, or once `READ_LINKS_MAX_CHARS` characters of hrefs and
|
|
284
|
+
their base are resolved (`links_truncated`). `browser_read`'s markdown goes
|
|
276
285
|
the same way (of the page's first article, else main, else body, with the browser's own text as its fallback), and
|
|
277
286
|
its frame scan reads the page's first 2,000,000 characters in steps that yield the loop. Outside Node's builtins and
|
|
278
287
|
undici it loads only node-html-parser and node-html-markdown, on demand and in that worker thread.
|
|
279
288
|
- `/durable`: the pi-durable adapter. `createBrowserExtension` is session custody in the run's own store (a create is
|
|
280
|
-
committed before the provider is called, release is a durable task, reconcile runs at run open).
|
|
281
|
-
`web_fetch` and `web_search`.
|
|
282
|
-
- `/coding-agent`: the pi coding agent's extension, described under [For pi users](#for-pi-users). `pi install` loads it.
|
|
289
|
+
committed before the provider is called, release is a durable task, reconcile runs at run open).
|
|
283
290
|
- `/driver/stagehand`: `stagehandDriver()`, Stagehand v4 over upstream's facade, vendored unedited in
|
|
284
291
|
`src/vendor/stagehand-facade/`. `UPSTREAM.json` names the commit and each file's blob id and SHA-256;
|
|
285
292
|
`node scripts/vendor-facade.mjs --check` verifies them and `--commit SHA --release NAME` re-vendors. Stagehand is created
|
|
286
|
-
sealed: no inference, no cache,
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
293
|
+
sealed: no inference, no cache, and no trace endpoint, so no trace is exported. Stagehand attaches one client to a browser
|
|
294
|
+
at a time: closing a driver disconnects it, so the next attach is allowed.
|
|
295
|
+
- `/driver/cdp`: `cdpDriver()`, the driver of every AgentRun browser computer (Browserbase's, Kernel's, or the computer
|
|
296
|
+
package's `local-chrome` provider's Chrome on this machine), over its CDP URL. Browserbase and Kernel browsers now
|
|
297
|
+
refuse run code and file uploads (`browser_upload`), and their snapshot is the raw-CDP list; every browser computer
|
|
298
|
+
uses one driver, this one, which runs no code and sets no file input. It is raw CDP: no Stagehand, and nothing loaded into the browser. `snapshot` is Chrome's
|
|
299
|
+
accessibility tree with the same "frame-node" ids (`[0-42]`: the frame's place, then Chrome's backend node id). `run`
|
|
300
|
+
takes actions only. Each action is scrolled into view, hit-tested at its centre, and pressed and released there, or
|
|
301
|
+
typed with inserted text and a real last key. Each answers one line: `[ok] click [0-42] button "Add" -> page changed`
|
|
302
|
+
(or `navigated to <url>`, or `no change`). `run` code is refused in words, and navigation is
|
|
303
|
+
`{"op":"goto","url":"https://..."}`. A frame another site runs in its own process (a cross-origin iframe) is not read:
|
|
304
|
+
the snapshot names each one it left out. Adapted from Browser Use Pi's `ax.ts`, `cdp.ts` and `page.ts` under its MIT
|
|
305
|
+
license, in `src/vendor/browser-use-pi/` (see NOTICE and that folder's `UPSTREAM.json`).
|
|
306
|
+
- `/providers/cdp`: where the package's own browsers come from: any CDP endpoint, or a local Chrome the provider starts and
|
|
307
|
+
kills by exact pid. A hosted browser is the host's provider (agentrun-serve's, over its computer providers).
|
|
290
308
|
- `/providers/chrome-args`: `chromeArgs()`, the arguments the cdp provider starts a local Chrome with, and `extensionOrigin()`,
|
|
291
309
|
the one Origin its DevTools socket allows (Stagehand's extension). A host that starts its own Chrome for Stagehand takes them
|
|
292
|
-
from here rather than copying Stagehand's `--remote-allow-origins=*`.
|
|
293
|
-
|
|
294
|
-
ends a browser: it hands that session to one custody at a time, and the host takes it back itself.
|
|
310
|
+
from here rather than copying Stagehand's `--remote-allow-origins=*`. `findChrome()` finds the Chrome to start: the one
|
|
311
|
+
`PI_BROWSER_CHROME` or `CHROME_PATH` names, else `google-chrome` or `chromium` on the PATH, else the usual install locations.
|
|
295
312
|
- `/live-view`: a person sees and drives the local Chrome (the cdp provider) from your page, with nothing leaving the machine but the model. See
|
|
296
313
|
[The live view of your own Chrome](#the-live-view-of-your-own-chrome).
|
|
297
|
-
- `/recorder`: `frameRecorder()` screencasts each session over DevTools into a sink you pass, and `exportFrameTracks()`
|
|
298
|
-
makes a WebM per session from the recorded frames. See [Recording what the browsers show](#recording-what-the-browsers-show).
|
|
299
314
|
- `/testing`: the shared test fake. A provider backend with a ledger of every call, a credential broker, an HTTP face so the
|
|
300
315
|
ledger outlives a killed child process, a driver over in-memory pages, and sentinel credentials. A host's composition
|
|
301
316
|
test and this package's crash matrix use the same one.
|
|
302
317
|
|
|
303
|
-
## For pi users
|
|
304
|
-
|
|
305
|
-
The pi coding agent gets `snapshot`, `run`, `screenshot`, `browser_read`, `browser_relaunch`, `browser_release` and
|
|
306
|
-
`web_fetch` (plus `web_search` when the provider offers one). It opens a Chrome of its own on first use, reads and drives
|
|
307
|
-
pages through Stagehand, files every page and screenshot with the page's URL and a SHA-256, and closes the Chrome when you
|
|
308
|
-
release it, after three idle minutes, or when the session ends. Nothing starts until the model's first browser call.
|
|
309
|
-
|
|
310
|
-
The local browser needs Chrome or Chromium: the one named by `--browser-chrome` or `PI_BROWSER_CHROME`, else `CHROME_PATH`,
|
|
311
|
-
else the first of `google-chrome`, `chromium` and the usual install locations (`/opt/google/chrome/chrome`, Chrome in
|
|
312
|
-
`/Applications`, Chrome in `Program Files`). It is tested on Linux; macOS and Windows are not verified.
|
|
313
|
-
|
|
314
|
-
| Setting | Meaning |
|
|
315
|
-
|---|---|
|
|
316
|
-
| `--browser-chrome PATH`, `PI_BROWSER_CHROME` | The Chrome to start. A path that does not exist is refused by name, never replaced. |
|
|
317
|
-
| `--browser-headed`, `PI_BROWSER_HEADED=1` | Show the window instead of running headless. |
|
|
318
|
-
| `--browser-no-sandbox`, `PI_BROWSER_NO_SANDBOX=1` | Start Chrome without its sandbox. Needed as root, in a container, or where user namespaces are restricted. Use it only for pages you trust. |
|
|
319
|
-
| `--browser-endpoint URL`, `PI_BROWSER_ENDPOINT` | Attach to a Chrome you already run (`http://host:port` or `ws://`) instead of starting one. Releasing leaves it running. |
|
|
320
|
-
| `--browser-provider browserbase`, `PI_BROWSER_PROVIDER` | Use Browserbase. Needs `BROWSERBASE_API_KEY` (`BB_API_KEY` also works); a missing key is refused by name. `PI_BROWSER_PROXIES=1` turns on its proxies. |
|
|
321
|
-
| `--browser-provider kernel`, `PI_BROWSER_PROVIDER` | Use Kernel. Needs `KERNEL_API_KEY`; a missing key is refused by name. `KERNEL_BASE_URL` points at another Kernel API. `PI_BROWSER_STEALTH=1` turns on Kernel's stealth mode. |
|
|
322
|
-
|
|
323
|
-
What it does with your machine and your data:
|
|
324
|
-
|
|
325
|
-
- The Chrome it starts has its own profile directory under a temporary root and a free debugging port, never your browser's
|
|
326
|
-
profile and never port 9222. The profile is deleted when the browser is released.
|
|
327
|
-
- Pages and screenshots are filed under `<project>/.pi/browser/evidence/`, each as a receipt (`tool`, `args`, `status`, the
|
|
328
|
-
page's final URL and title, `sha256`, then the body). A credential-shaped query parameter in a URL, a Bearer value and a
|
|
329
|
-
key of the shapes Stagehand knows are replaced by `[redacted]` before anything is filed, shown to the model or stored.
|
|
330
|
-
- Each browser session is appended to the pi session file (`browser.session` entries; the model never sees them). The coding
|
|
331
|
-
agent has no mid-turn resume, so a resumed session gets a fresh browser: cookies and page state do not carry over. A Chrome
|
|
332
|
-
that a crashed pi left running is closed when that session is next started, never adopted.
|
|
333
|
-
- Stagehand's trace export is pointed at a closed loopback port, so nothing you browse goes to a third party.
|
|
334
|
-
- `browser_relaunch` with `verified` or `geolocation` changes nothing on a local Chrome or on Kernel; they are Browserbase features.
|
|
335
|
-
With proxies off (the default), a `geolocation` is refused and the session is left as it was, as in the pi-durable adapter.
|
|
336
|
-
- A host that builds the extension with `policy: { actions: "deny" }` or `"ask"` asks for requests to be held, and the coding
|
|
337
|
-
agent has no request observer to hold them. So under either it starts no browser: every browser tool answers
|
|
338
|
-
`browser_unavailable`, naming the action policy, and `web_fetch` still works. Set `actions: "allow"` (or leave it out) to
|
|
339
|
-
browse, or use the pi-durable adapter (`/durable`), which holds requests under `deny` and `ask`.
|
|
340
|
-
|
|
341
|
-
Providers and `web_fetch`:
|
|
342
|
-
|
|
343
|
-
- Without a fetch service, `web_fetch` reads public hosts only. It refuses loopback, private, link-local and other
|
|
344
|
-
special-purpose addresses and any port but 80 and 443 at every redirect hop, anything over 5 MiB, and non-text, and it
|
|
345
|
-
sends no cookies or credentials. The call's signal bounds every hop, its name lookup included.
|
|
346
|
-
- A PDF the fetch service will not convert to markdown (Browserbase answers HTTP 400) is fetched once more as the raw file.
|
|
347
|
-
The coding agent has no PDF text extractor, so `web_fetch` says the URL is a PDF and that `format: "raw"` returns its
|
|
348
|
-
bytes, base64-encoded. A host with an extractor passes `pdf: { text(bytes, url, signal) }` to `createWebExtension`; the text
|
|
349
|
-
it returns is answered and filed as the page (`extractor: pdf-text`, judged by `classifyPage` like any page). A PDF over
|
|
350
|
-
32 MiB is not handed to it, and it gets 120 s (`maxBytes`, `timeoutMs`); a PDF with no text says so.
|
|
351
|
-
- On Kernel, each session is tagged with its run and lease tag, so a crashed pi's session is found again by tag. It is
|
|
352
|
-
created with an idle timeout equal to the idle release (three minutes), so Kernel ends a browser nobody is connected to if
|
|
353
|
-
pi dies, and a release deletes it and waits until Kernel shows it gone. Stagehand's extension must be stored in your Kernel
|
|
354
|
-
project: a stored extension with the same bytes (Kernel's checksum) is used whatever its name and never changed, and
|
|
355
|
-
otherwise the first session uploads it once as `agentrun-stagehand-<sha256 prefix>`. A plan with no room for it fails the
|
|
356
|
-
launch naming `insufficient_plan`. Kernel's live view is not offered, because its API has no read-only form of it. Kernel
|
|
357
|
-
calls go direct, never through `HTTP(S)_PROXY`, as Browserbase's do; a host behind a proxy passes its own `fetch` to `kernelProvider`.
|
|
358
|
-
|
|
359
|
-
Limits: a crash loses the in-flight turn and the browser with it. `pi install` pulls Stagehand, about 40 MB and 52 packages
|
|
360
|
-
with its dependencies.
|
|
361
|
-
|
|
362
318
|
## For hosts
|
|
363
319
|
|
|
364
320
|
Any pi-durable `Harness` can install the extensions. A local Chrome is the default provider and costs nothing.
|
|
@@ -388,16 +344,19 @@ await browser.reconcile(harness, () => true, context); // settles what a dead
|
|
|
388
344
|
`createBrowserExtension` takes no key and sends nothing anywhere but the provider you give it. The options:
|
|
389
345
|
|
|
390
346
|
- `driver`: `stagehandDriver()`, or your own `DriverFactory`.
|
|
391
|
-
- `provider`:
|
|
392
|
-
|
|
347
|
+
- `provider`: the local Chrome (`cdpProvider`), or your own `BrowserProvider` over a hosted vendor, with your own metadata
|
|
348
|
+
stamped on every session.
|
|
393
349
|
- `evidence`: a sink that files each read where your receipts already are.
|
|
394
350
|
- `onSession`: the host channel. It receives each session's row and, only there, the live-view URLs. Nothing in the run log, a
|
|
395
351
|
result or a log line carries them.
|
|
396
352
|
- `decisions`: `classifyPage` and `rankChunks`, answered with your judge. Absent, no page is classified and no find is ranked.
|
|
397
353
|
- `redact.values`: exact strings to scrub besides the built-in shapes.
|
|
398
354
|
- `section.addendum`: your text after the package's prompt section.
|
|
399
|
-
- `
|
|
400
|
-
|
|
355
|
+
- `signIns`: `true` when the plane's sessions open on the agent's saved sign-ins (your kept profile or context). `run`'s
|
|
356
|
+
description then tells the model the browser keeps them, for a page behind a sign-in; without it, it says only that the
|
|
357
|
+
browser keeps cookies across pages. Absent, it is whether a `sessionVault` is given.
|
|
358
|
+
- `workspace`: per conversation, the `DownloadsWorkspace` that `browser_downloads` writes through: the host's own file calls on its workspace (read, stat, mkdir, write, writeNew, remove), each path relative to the workspace and none following a link on the way or at its end, a read refusing anything but a regular file without waiting on it. Absent, `browser_downloads` is not listed.
|
|
359
|
+
- `files`: a `WorkspaceFiles` that resolves `browser_upload` paths (`workspaceFiles(folder)` is one). Absent, `browser_upload` is not listed.
|
|
401
360
|
- `handoff`: a `HandoffPort` that reaches a person (`request`, then `outcome` polled until done, cancelled or expired;
|
|
402
361
|
when a request expires is the port's to decide). Absent, `browser_request_handoff` is not listed.
|
|
403
362
|
- `prices`: your session price (for example from `BROWSERBASE_USD_PER_MINUTE`). It prices the session meter, so each session
|
|
@@ -406,15 +365,36 @@ await browser.reconcile(harness, () => true, context); // settles what a dead
|
|
|
406
365
|
final, state }`, called in the commit that writes it on the session's record, so a host that books it in `tx` books
|
|
407
366
|
exactly what the record bills: at a browser call (`call.callId`), what the session ran since its last charge; at its
|
|
408
367
|
release, or when custody gives up releasing it (`lost`) (`final`), the rest, topped up to `prices.sessionMinimumS`. A session already billed in full is never charged
|
|
409
|
-
again. `state` is `priced`, or `unpriced`/`invalid` with `usd` 0 (no price, not $0).
|
|
410
|
-
|
|
368
|
+
again. `state` is `priced`, or `unpriced`/`invalid` with `usd` 0 (no price, not $0). `overbookedS`, when present: an
|
|
369
|
+
earlier charge billed the session past this one's `at` (a `handle.charge` taken while its release was under way, the
|
|
370
|
+
release confirmed before it), by that many seconds; this charge bills none of it again and never a negative. It must
|
|
371
|
+
not throw: a throw fails the commit, and a call's charge is then carried by the session's next one.
|
|
372
|
+
- `onRaceReleased({ conversationId, tag, ids, madeAt })`: a release by a session's tag ended sessions besides that session's own
|
|
373
|
+
(a create retried behind the provider's API, or a create race of that tag, left them running), and no record bills
|
|
374
|
+
their time. Called with their ids once a status read confirms each stopped, including one whose release stopped it and
|
|
375
|
+
then failed. Each id is saved on the session's inventory row (`owed`) before its stop is sent, and stays there, across
|
|
376
|
+
a restart, until a read confirms its stop and it is told: the session's own release confirms the ones its row owes, and
|
|
377
|
+
a run open's reconcile those of a row that ended lost or that a release left owing. Called again for an id only when a
|
|
378
|
+
process ends between the call and the commit that takes it off the row, so a host books what they ran under one key
|
|
379
|
+
per id. `madeAt`, by id, is when the provider made each, where its tag lookup said (`LeaseRef.madeAt`): saved on the
|
|
380
|
+
row (`made`) with the id before its stop is sent, so a later process, whose lookups no longer list a stopped session,
|
|
381
|
+
hands it on too; absent when the lookup said for none. A throw here never fails the release.
|
|
411
382
|
|
|
412
383
|
Per conversation, the host writes a `BrowserConfig` (`label`, `run`, and the policy: proxies, verified, captcha, geolocation,
|
|
413
384
|
region, a raw context id, the session timeout, the idle release and the batch timeout; `DEFAULT_BROWSER_POLICY` holds the
|
|
414
385
|
package's defaults to spread and override) in the conversation's creating commit,
|
|
415
386
|
selects the extensions for it, and calls `handle.release(conversation, "close", ctx)` when the conversation ends. Releases run
|
|
416
387
|
as background tasks, which `waitForIdle` skips and closing the harness aborts: before it closes, a host calls
|
|
417
|
-
`handle.drain(harness, ctx, signal?)`, which resolves once none is live. A
|
|
388
|
+
`handle.drain(harness, ctx, signal?)`, which resolves once none is live. A host that closes with no drain after its `close`
|
|
389
|
+
releases gets them at the provider all the same: `handle.close()` waits, 30 s at most, for every one no drain since covered.
|
|
390
|
+
A host that stops waiting on a release calls `handle.charge(conversation, ctx)` to book the time known so far: each session
|
|
391
|
+
still open (live, held, or releasing) is billed through now, not final, its `chargedThrough` moved in the same commit, and
|
|
392
|
+
the release's own charge, when it lands, bills only the time after it. A record with no session id yet (its create under
|
|
393
|
+
way, or its answer lost and the session not yet found by its tag) is not charged: its release's charge bills the whole
|
|
394
|
+
session once it is found. A session already charged through now gets no $0 charge. The row `onSession` is told at a
|
|
395
|
+
release is the session as its release confirmed it: a `handle.charge` taken after that confirm and before its commit
|
|
396
|
+
bills past it, and is in the charges (`onCharge`, the bill) but not in that row, whose `spent` is then short of the
|
|
397
|
+
record's by that charge. A release the store cannot record (a storage error)
|
|
418
398
|
is still made at the provider, and the record is left for the next run's reconcile; once the store has failed,
|
|
419
399
|
`handle.close()` releases every session the process still holds, and over a healthy store it releases nothing. At run open,
|
|
420
400
|
after the extensions are installed and
|
|
@@ -437,113 +417,22 @@ and `search`.
|
|
|
437
417
|
|
|
438
418
|
Two things to know before you give a model a browser:
|
|
439
419
|
|
|
440
|
-
- **What a model may reach is your decision.** `
|
|
441
|
-
|
|
442
|
-
their network goes. A host that must not let a model reach internal addresses restricts that network or the URLs it passes.
|
|
443
|
-
- **The Browserbase provider changes the process.** Its first call that needs the Browserbase client adds Browserbase's hosts to `NO_PROXY` and `no_proxy`, and
|
|
444
|
-
the first attach replaces `globalThis.WebSocket` with a wrapper that dials a bound credential proxy instead of the raw
|
|
445
|
-
connect URL. Both are process-wide. The wrapper passes every other URL through unchanged. Importing the package does
|
|
446
|
-
neither.
|
|
447
|
-
|
|
448
|
-
### Recording what the browsers show
|
|
449
|
-
|
|
450
|
-
`@parcha/pi-browser/recorder` screencasts each session over DevTools (a local Chrome, Browserbase and Kernel all speak it) and hands
|
|
451
|
-
`agentrun.recording/1`'s `frame` and `frame.gap` lines, with their JPEGs, to a sink you pass. It is read-only beside the session's own
|
|
452
|
-
connections, and it writes nothing itself.
|
|
453
|
-
|
|
454
|
-
```js
|
|
455
|
-
import { frameRecorder } from "@parcha/pi-browser/recorder";
|
|
456
|
-
|
|
457
|
-
const frames = frameRecorder({
|
|
458
|
-
clock: () => Date.now() - started, // ms since the recording started: every line's `t`
|
|
459
|
-
gen: () => generation, // optional: this process's generation, on every line
|
|
460
|
-
lastFrameAt: (session) => lastFrameT(session), // optional: where an earlier process's frames for a session stopped
|
|
461
|
-
sink: (line, blobs = {}) => { // blobs: sha256 hex -> JPEG bytes; the sink keeps blobs/<sha256>.jpg and adds `seq`
|
|
462
|
-
for (const [sha, bytes] of Object.entries(blobs)) fs.writeFileSync(`blobs/${sha}.jpg`, bytes);
|
|
463
|
-
events.write(JSON.stringify({ ...line, seq: seq++ }) + "\n");
|
|
464
|
-
},
|
|
465
|
-
});
|
|
466
|
-
const browser = createBrowserExtension({ provider: ({ conversationId }) => frames.watch(provider, conversationId), driver, evidence });
|
|
467
|
-
```
|
|
468
|
-
|
|
469
|
-
A session is captured from the moment it is created or reattached (so after a kill the same session resumes by itself). The lines:
|
|
470
|
-
|
|
471
|
-
```json
|
|
472
|
-
{"channel":"live","source":"browser","kind":"frame","gen":1,"t":20123,"conv":3,"data":{"session":"bb_4e1a","provider":"browserbase","w":800,"h":500,"mime":"image/jpeg"},"blobs":["9c0e..."]}
|
|
473
|
-
{"channel":"live","source":"browser","kind":"frame.gap","gen":2,"t":26004,"conv":3,"data":{"session":"bb_4e1a","from":21004,"reason":"process_killed"}}
|
|
474
|
-
```
|
|
475
|
-
|
|
476
|
-
- Capture is JPEG at quality 60, at most 800 px wide and 10 frames a second per session (the newest frame wins), of the page the agent is using.
|
|
477
|
-
Every line carries the `conv` of the conversation that owns the session (given to `watch`, or read from the lease tag); a session whose
|
|
478
|
-
conversation cannot be told is not recorded.
|
|
479
|
-
- A gap is written, never filled: `process_killed` when a session this process did not create is taken up and `lastFrameAt` knows its last
|
|
480
|
-
frame, `session_released` when the session is released, `credential_on_page` while a credential is on the page.
|
|
481
|
-
- **No frame is kept while a credential or a code is on the page**, and anything the recorder cannot read counts as one being there. A frame is
|
|
482
|
-
judged against the page the moment it arrives (one check, standing for the page at its capture) and again when its turn to be kept comes (both
|
|
483
|
-
checks go through one pace per session: each is sent at least 50 ms after the last, so a session sends at most 20 `Runtime.evaluate` in any
|
|
484
|
-
second, however fast frames arrive); a credential seen in either drops it, and a frame held across a navigation or a move to another page is not kept. The check looks at password
|
|
485
|
-
fields, `one-time-code` fields and fields named like a code (name, id, `<label>`, `aria-labelledby`, `aria-label` or placeholder says otp, totp,
|
|
486
|
-
2fa, passcode, ...) that hold a value, in the page, open shadow roots and same-origin frames; a value typed and cleared between two checks is
|
|
487
|
-
still seen (the page keeps a flag, `window.__piFramesSecret`, set by the fields' own `input` events). A page that nests deeper than the check
|
|
488
|
-
reads (eight shadow roots or frames) and a visible frame whose content it cannot reach (another origin: a payment or sign-in widget) count as
|
|
489
|
-
a credential present; a frame with no area, or not displayed, is not a picture of anything and does not. A page that cannot be checked at all
|
|
490
|
-
is not recorded. The pause lasts until the page navigates and the check is clean; the gap says why in `data.detail` (`field`, `typed`,
|
|
491
|
-
`too_deep`, `unreadable_frame` or `host`). What no script in the page can see (a closed shadow root, a value set by script with no event) is the
|
|
492
|
-
host's to pause with `frames.pause(session)` (lifted with `frames.resume(session)`).
|
|
493
|
-
A host that lets a person drive a session (the live view) passes `hold: (ref) => boolean`: while it answers `true` for a session no frame is stored and one gap
|
|
494
|
-
(`credential_on_page`, detail `host`) marks the span, not one per skipped frame; when it answers `false` frames resume. A hold that throws counts as `true`.
|
|
495
|
-
The screencast sends a frame only when the page repaints, and a person's login has often already left the page, so when a hold lifts the recorder captures one frame of the page as it is then (a one-off screenshot of the followed session, judged like any other: a field still holding a credential makes it the credential gap, not a frame); a capture that fails costs that frame only. No new option. A withheld frame never counts as the last frame kept, so a `session_released` gap inside a hold starts at the last frame stored before it.
|
|
496
|
-
- A live-view URL is never recorded or asked for: the recorder reads only the session's DevTools socket and never writes its address.
|
|
497
|
-
- Lines reach the sink one at a time, in order. A sink that throws, rejects or does not answer within `sinkTimeoutMs` (5 s) cannot fail a browser
|
|
498
|
-
call: that line is dropped and counted in `frames.stats()`, and a frame that was not saved never becomes the point a later gap starts from.
|
|
499
|
-
- `frames.watch(...).release` ends the capture, and writes the `session_released` gap, once the provider has released the session: a release it
|
|
500
|
-
refuses leaves the capture running.
|
|
501
|
-
- **`frame.track`** (a WebM per session with an index) is made at export, from the recorded frames, by `exportFrameTracks`:
|
|
502
|
-
|
|
503
|
-
```js
|
|
504
|
-
import { exportFrameTracks } from "@parcha/pi-browser/recorder";
|
|
505
|
-
const tracks = await exportFrameTracks({ lines, readBlob: (sha256) => bytesOfBlob(sha256), endAt: recordingEndMs, fps: 10 });
|
|
506
|
-
for (const { line, blobs } of tracks) { /* line is the frame.track line; blobs holds the WebM and its index by sha256 */ }
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-
One track per session that has a frame. The video is VP9 at a constant `fps` (default 10) on one canvas, the largest frame in even numbers (a smaller
|
|
510
|
-
frame is centred on it); each frame is shown until the next one, and while a gap lasts the video shows a slate: from the moment a
|
|
511
|
-
`credential_on_page` or `session_released` gap was written, and from the last frame the earlier process saved for a `process_killed` gap (nothing is
|
|
512
|
-
known after it). The track runs from the session's first frame to `endAt` (default: the last line, a lone frame lasting one frame's time). The line is
|
|
513
|
-
`{ kind: "frame.track", t: <the track's end>, conv, data: { session, fps, from, to }, blobs: [<webm sha256>, <index sha256>] }`; the index (JSON) lists every
|
|
514
|
-
frame with its `t` and its `ms` offset into the video, and every gap with `from`, `to`, `reason` and `detail`, so a viewer maps a time in the recording to a
|
|
515
|
-
time in the video (`t - from`). A frame whose blob is missing, does not hash to its name or is not a JPEG shows the slate and is reported in `skipped`.
|
|
516
|
-
The step starts `ffmpeg` (`ffmpeg` option: a path; default the one on the PATH) in a private temporary directory with `PATH`, `LANG`, `LC_ALL` and `HOME`
|
|
517
|
-
only, with fixed arguments and no URL, a timeout (`timeoutMs`, 120 s) and an `AbortSignal`; a failure is a `TrackExportError` (`ffmpeg_missing`,
|
|
518
|
-
`ffmpeg_failed`, `ffmpeg_timeout`, `aborted`) and writes nothing.
|
|
519
|
-
|
|
520
|
-
## How it compares
|
|
521
|
-
|
|
522
|
-
Our own bench, run by this package's authors with `gpt-6-luna` only, 3 samples per case, against `pi-agent-browser-native`
|
|
523
|
-
0.9.3 on the same prompts and model. Five cases are public-registry lookups (two behind walls, where abstaining is the right
|
|
524
|
-
answer); three are loopback fixtures. Treat it as ours, not independent.
|
|
525
|
-
|
|
526
|
-
- Local Chrome, 48 runs: no wrong answers from either; median $0.0013 a run against $0.0024, 6 tool calls against 9, 7 tool
|
|
527
|
-
errors in 180 calls against 85 in 260, and no process left running after a run, against a browser daemon left after each one.
|
|
528
|
-
- Browserbase, 30 runs: a tie on outcomes (5 correct, 10 abstentions, 0 wrong for each). This package's median was $0.0034 a
|
|
529
|
-
run against $0.0046, with more tool calls on the walled cases (16 against 12).
|
|
530
|
-
- A crash in the middle of a form submit is covered by neither: with a scripted model both submitted twice, and a resumed
|
|
531
|
-
model that was not told about the cut call repeated the submit in 0 of 10 runs for each.
|
|
532
|
-
- Much of the other arm's tool-error count is how luna calls that tool, not the extension. Another model may give other numbers.
|
|
420
|
+
- **What a model may reach is your decision.** `publicFetch` refuses private addresses, but a driven browser goes
|
|
421
|
+
wherever its network goes. A host that must not let a model reach internal addresses restricts that network or the URLs it passes.
|
|
533
422
|
|
|
534
423
|
## Development
|
|
535
424
|
|
|
536
425
|
```sh
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
CHROME_PATH=/path/to/chrome
|
|
426
|
+
pnpm --filter @parcha/pi-browser run build
|
|
427
|
+
pnpm --filter @parcha/pi-browser test # everything but the real-Chrome suites
|
|
428
|
+
CHROME_PATH=/path/to/chrome pnpm --filter @parcha/pi-browser run test:chrome
|
|
540
429
|
```
|
|
541
430
|
|
|
542
|
-
The real-Chrome suites (`stagehand_real_chrome`, `cdp_local_chrome`, `effects-chrome`, `
|
|
431
|
+
The real-Chrome suites (`stagehand_real_chrome`, `cdp_local_chrome`, `effects-chrome`, `screenshot_clip_real_chrome`,
|
|
543
432
|
`readme_example`) skip with a typed reason where no Chrome can load Stagehand's extension, and fail instead under
|
|
544
433
|
`AGENTRUN_REQUIRE_LOCAL_CHROME=1`, which CI sets. The crash matrix (`test/custody.test.mjs`) SIGKILLs a child process at each
|
|
545
434
|
cut point of a session's life against the shared fake and reopens the run's SQLite file. The wire checks (`test/wire/`) plant
|
|
546
|
-
sentinel credentials in a fake provider and scan every byte a run produced. The suites run on Node 22
|
|
435
|
+
sentinel credentials in a fake provider and scan every byte a run produced. The suites run on Node 24.22.3, the minimum the package supports.
|
|
547
436
|
|
|
548
437
|
Apache-2.0. Copyright 2026 Parcha Labs, Inc. `NOTICE` records the Stagehand (MIT) code this package copies: the Chrome launch
|
|
549
438
|
flags and the vendored facade.
|