@capybara-hq/plugin-browser 0.1.0-rc.1 → 0.1.0-rc.10
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/.capybara-plugin/plugin.json +3 -3
- package/README.md +191 -24
- package/dist/index.mjs +409 -118
- package/package.json +2 -2
- package/ui/panel.js +922 -132
- package/ui/service/daemon.mjs +3129 -464
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"name": "browser",
|
|
4
|
-
"version": "0.1.0-rc.
|
|
4
|
+
"version": "0.1.0-rc.10",
|
|
5
5
|
"publisher": "Capybara",
|
|
6
6
|
"description": {
|
|
7
7
|
"en": "A real browser in the conversation owner's device for agents: navigate, read and act on pages through tools, with a live view in the conversation panel and takeover by the person",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"entry": "./dist/index.mjs",
|
|
18
18
|
"manifest": {
|
|
19
19
|
"name": "browser",
|
|
20
|
-
"version": "0.1.0-rc.
|
|
21
|
-
"sdk": "^0.1.0-rc.
|
|
20
|
+
"version": "0.1.0-rc.10",
|
|
21
|
+
"sdk": "^0.1.0-rc.75",
|
|
22
22
|
"provides": [],
|
|
23
23
|
"requires": [],
|
|
24
24
|
"optional": [],
|
package/README.md
CHANGED
|
@@ -26,9 +26,16 @@ A real browser in the person's device for agents (browser use spec,
|
|
|
26
26
|
`ctx.deviceAccess.ensureService` (files: every file under `ui/service/`, read once per
|
|
27
27
|
extension instance), sends one `ToolRequest` and reports the hosts the device refused with
|
|
28
28
|
`reportBlockedHosts` (the kernel raises the network ask and reruns the call once allowed).
|
|
29
|
+
Every request carries the call's `conversationId` and `rootConversationId` from the kernel's
|
|
30
|
+
tool call context (written after the operation, never from tool input). A result names the
|
|
31
|
+
conversation's active tab, or says "This conversation has no browser tab yet.", and every result
|
|
32
|
+
the daemon answered, ok or error, ends with "Tabs open in this conversation: N of 6.".
|
|
29
33
|
- `browser_handoff` sends the daemon a handoff notice (the panels show a banner with 完成 / 取消),
|
|
30
|
-
then raises an `InputRequired` question `{ done: boolean }` in the conversation
|
|
31
|
-
|
|
34
|
+
then raises an `InputRequired` question `{ done: boolean }` in the conversation, with `open`
|
|
35
|
+
naming the `browser` panel so the person's conversation page opens it. The question's title is
|
|
36
|
+
请在浏览器中完成:<the reason's first sentence> / Finish in the browser: …, the body is the full
|
|
37
|
+
reason, and `choices` draw 完成 (true, primary) and 取消 (false) as buttons. It stays a boolean
|
|
38
|
+
because the kernel's `answerHandoff`, which the banner uses, answers `{ done }`. On
|
|
32
39
|
resume it clears the notice (with Done also handing the browser back, so a takeover the person
|
|
33
40
|
still holds ends) and returns the page snapshot, or fails with "The user cancelled the handoff;
|
|
34
41
|
ask the user how to continue, or try another approach.".
|
|
@@ -38,41 +45,201 @@ A real browser in the person's device for agents (browser use spec,
|
|
|
38
45
|
- Panel routes: `GET /ui/browser` (the page) and `GET /ui/panel.js` are public; `POST
|
|
39
46
|
/ui/stream-ticket`, `/ui/network-hosts` and `/ui/handoff-answer` are `embed` routes that take
|
|
40
47
|
the org, account and conversation from the caller only (a platform-scope token or one without a
|
|
41
|
-
conversation gets 403).
|
|
42
|
-
|
|
48
|
+
conversation gets 403). `/ui/handoff-answer` takes `{ callId, handoffConversationId, done }`:
|
|
49
|
+
the panel echoes the handoff's conversation from the daemon's `state.handoffs` (a sub-agent's,
|
|
50
|
+
in the root's panel), and the kernel answers only for the scope conversation or a descendant.
|
|
51
|
+
The panel never starts the service: a ticket is minted either way, and a stopped service closes
|
|
52
|
+
the viewer with 4404 (the panel's "not running" state).
|
|
43
53
|
|
|
44
54
|
## The daemon (`daemon/`)
|
|
45
55
|
|
|
46
|
-
- Chromium starts on the daemon's first start.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
- Chromium starts on the daemon's first start. On Linux devices (device-docker, device-e2b) it is
|
|
57
|
+
the full Chromium build in its new headless mode, so the browser presents as an ordinary Chrome:
|
|
58
|
+
Chrome's own reduced user agent for the platform (`--user-agent`, never "HeadlessChrome"), the
|
|
59
|
+
browser's own client hints, a window the size of the viewport, the device's locale and time zone.
|
|
60
|
+
On macOS (device-local) too where the machine's capybara-device says its sandbox allows it
|
|
61
|
+
(`CAPYBARA_SERVICE_MACH=chromium`, capybara-hq/core#843); the browser gets `MAC_CHROMIUM_TMPDIR`
|
|
62
|
+
and crash reporting off. An older capybara-device keeps the headless shell in one process (and
|
|
63
|
+
nothing larger is downloaded). First start there: one download into the install directory (about 377 MB, 16 s on a fast
|
|
64
|
+
link), one restart, then about 2 s to launch. Nothing spoofs a fingerprint, solves a CAPTCHA or
|
|
65
|
+
hides automation beyond Playwright's own flags (`navigator.webdriver` stays true).
|
|
66
|
+
- Where the browser comes from (plugins#209: never from a place the service or an agent command
|
|
67
|
+
could write once it runs): the provider's install directory `CAPYBARA_SERVICE_INSTALL`
|
|
68
|
+
(device-local) is filled on the first start, sealed with `.sealed`, and the daemon answers
|
|
69
|
+
`restart` and exits, so every later start runs it read only (the plugin starts the service again
|
|
70
|
+
within the same tool call, waiting while `ensureService` still reports the exiting process's
|
|
71
|
+
start time, for at most 30 s; an unsealed directory is always installed afresh, never trusted as
|
|
72
|
+
found); else a `PLAYWRIGHT_BROWSERS_PATH` the daemon cannot write, outside the workspace
|
|
73
|
+
(device-docker / device-e2b ship it in `/opt/capybara-browsers`, pinned to this package's
|
|
74
|
+
playwright-core): this build's revision, else the newest revision of the build there. Nothing
|
|
75
|
+
else: without such a place the browser does not start and says how to get one (update
|
|
76
|
+
capybara-device; recreate a cloud device on the current image). It never installs where it
|
|
77
|
+
could rewrite the browser itself.
|
|
78
|
+
- Uploads are read by the daemon (opened without following a final link, accepted only when the
|
|
79
|
+
resolved path lies in the workspace and names the very file opened) and handed to Chromium from
|
|
80
|
+
memory, at most 50 MiB; downloads are copied from Playwright's private file into an exclusively
|
|
81
|
+
created file in `<workspace>/downloads`, checked to be that directory's own before any byte is
|
|
82
|
+
written. So a link the agent plants in the workspace never makes the service read or write its
|
|
83
|
+
own profile.
|
|
84
|
+
- The network: Chromium sends everything, loopback included, through the device's proxy
|
|
85
|
+
(`HTTPS_PROXY` / `HTTP_PROXY` of the service, the same proxy and rules as the device's commands:
|
|
86
|
+
the proxy resolves the name, with the fake-IP DNS fallback, and judges the address). A proxy URL
|
|
87
|
+
with credentials goes to Playwright's `proxy` option, which answers the challenge by
|
|
88
|
+
intercepting requests; under that interception Chromium loses a request it restarts for an
|
|
89
|
+
ACCEPT_CH frame (www.google.com sends one), so the daemon disables `AcceptCHFrame` (its
|
|
90
|
+
`--disable-features` repeats Playwright's own list: Chromium takes only the last flag), and
|
|
91
|
+
`--disable-auto-reload` keeps a network error page from reloading itself (that reload aborted
|
|
92
|
+
the agent's next navigation in the tab).
|
|
93
|
+
- A navigation that fails says why (`unreachable`): Chromium's net error with its meaning, and
|
|
94
|
+
for a failed tunnel what the device's proxy answers for the host (refused by the network
|
|
95
|
+
settings: `blocked`; could not connect: the name did not resolve, or the host refused or did not
|
|
96
|
+
answer). A navigation with no page within 30 s is stopped (CDP `Page.stopLoading`: one left in
|
|
97
|
+
flight keeps the page's queries waiting), so the tab shows its previous page and the next
|
|
98
|
+
request works on it. A 204 / 205 answer says so. The tab list runs beside the actions, and a
|
|
99
|
+
reply's title and verification check are bounded (2 s), so neither waits on a hanging page.
|
|
100
|
+
- A launch that fails (no download, a refused network) does not stop the daemon: every request
|
|
101
|
+
answers the cause and launches again. When the device's proxy refuses Playwright's download
|
|
102
|
+
hosts (`cdn.playwright.dev`, `playwright.download.prss.microsoft.com`, `storage.googleapis.com`
|
|
103
|
+
where the CDN redirects the download, or `PLAYWRIGHT_DOWNLOAD_HOST`), the reply lists them as
|
|
104
|
+
blocked hosts, so the person is asked to allow them.
|
|
105
|
+
- Verification pages (bot checks, CAPTCHAs: recognised by URL, title, a visible CAPTCHA widget,
|
|
106
|
+
or a 418 / 429 document): every tool result while one shows starts with a note telling the agent
|
|
107
|
+
to call `browser_handoff` instead of solving it or switching sites, and the viewer's tab state
|
|
108
|
+
carries `blocker: { kind: "verification", url }` on that tab (cleared when its page changes) for
|
|
109
|
+
the panel's "需要你完成验证" strip.
|
|
53
110
|
- The daemon stops after 15 minutes without requests and viewers. A pending handoff keeps it
|
|
54
111
|
running for up to 24 hours after its notice (the person may take a while to sign in); the
|
|
55
112
|
device's own idle suspension can still stop it sooner, and then the question stays open in the
|
|
56
113
|
conversation without its banner until the browser runs again.
|
|
57
|
-
- `<state>/session.json` keeps the open tabs' URLs
|
|
114
|
+
- `<state>/session.json` keeps the open tabs' URLs with their owners and, per conversation, the
|
|
115
|
+
active tab, the pending handoff and park (an older file is not restored). A daemon started within
|
|
58
116
|
10 minutes of the last write (a provider that restarts the service for a network change, see
|
|
59
117
|
device-local) reopens them; an idle stop removes the file. The profile keeps cookies and storage
|
|
60
118
|
on its own.
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
|
|
119
|
+
- `<state>/cookies.json` holds the persistent cookies from the moment a stop begins until the next
|
|
120
|
+
start has merged the ones the profile lacks (then it is removed, so a logout while the browser
|
|
121
|
+
ran is never undone by an old file). It exists because the service's kill (2 s after SIGTERM)
|
|
122
|
+
can land while a loaded Chromium is still writing its Cookies file. It lives in the service
|
|
123
|
+
state directory, outside every workspace and project (core `packages/device`), mode 0600, and
|
|
124
|
+
holds what Chromium's own `profile/Default/Cookies` holds there. That file is not protected
|
|
125
|
+
either: the daemon runs Chromium with `--use-mock-keychain`, so its values are only obfuscated
|
|
126
|
+
with a key every Chromium shares (observed: `encrypted_value` of 51 bytes, readable by anyone
|
|
127
|
+
who can read the directory). The JSON therefore adds no exposure.
|
|
128
|
+
- A `handoff_clear` with `handback` (the person answered Done) also ends a takeover. A handoff is
|
|
129
|
+
kept per conversation (at most one each) and dropped only by that conversation's next request.
|
|
130
|
+
- Viewer input (mouse, keys, text, address bar, tab open / switch / close) is applied only while
|
|
131
|
+
the person holds control: in the watch state a viewer may only choose its shown tab (`show`, a
|
|
132
|
+
tab of its tree) and move another conversation's tab here (`tab` `adopt`); any other input is
|
|
133
|
+
dropped on arrival, and input
|
|
134
|
+
still queued when control returns to the agent is dropped too (input already running, a navigation
|
|
135
|
+
or a long paste, finishes). Keys and buttons the person still holds are released when control
|
|
136
|
+
returns to the agent or the viewer ends, each on the tab where it was pressed (a held button after
|
|
137
|
+
moving the pointer outside the viewport, so the release completes no click), so the agent never
|
|
138
|
+
inherits a held Shift or a drag. Mouse moves are coalesced (the newest position wins while one
|
|
139
|
+
waits). After a move, click or scroll the daemon answers the page's cursor under the pointer
|
|
140
|
+
(`cursor`, only when it changed), off the input queue (the newest position wins, one lookup at a
|
|
141
|
+
time, an answer later than 200 ms is dropped) and without page code: CDP hit-tests the point
|
|
142
|
+
(`DOM.getNodeForLocation`, through shadow roots and in-process frames) and a function in an
|
|
143
|
+
isolated world reads the computed `cursor`, resolving `auto` as Chromium does (an I-beam over
|
|
144
|
+
editable fields and text); `pointer-events: none` elements are skipped as Chromium does;
|
|
145
|
+
out-of-process frames are entered through their own session (at most 20 frames looked at, 3
|
|
146
|
+
levels, matched in the page's coordinates), detached with their frame or when the viewer leaves
|
|
147
|
+
the page.
|
|
148
|
+
- Frames are binary messages (`encodeFrame`: tag, seq, width, height, JPEG); every other message is
|
|
149
|
+
JSON. Pacing (`daemon/viewer-pacing.ts`): the daemon pings each viewer every second (the path's
|
|
150
|
+
own round trip) and compares each frame's ack round trip with it. While frames take longer than
|
|
151
|
+
120 ms over it (a click would wait that long behind them on the slowest hop), it lowers the JPEG
|
|
152
|
+
quality (60, 45, 35, 25) and then the scale (down to half), allows only one frame in flight, and
|
|
153
|
+
steps back up after six quick frames. At most 15 frames per second; only the newest frame waits
|
|
154
|
+
(a stale one is replaced), and Chromium encodes the next frame at most every 500 ms while one
|
|
155
|
+
waits. JSON messages (state, cursor, pings, dialogs) never wait behind a held frame.
|
|
156
|
+
|
|
157
|
+
## Tabs
|
|
158
|
+
|
|
159
|
+
Tab ownership spec, `docs/superpowers/specs/2026-11-25-browser-tab-ownership-design.md` in
|
|
160
|
+
capybara-hq/core. One daemon, one Chromium and one profile per device stay: logins and cookies are
|
|
161
|
+
shared by every conversation, the tabs are not.
|
|
162
|
+
|
|
163
|
+
- **Owned per conversation.** Every tab belongs to one conversation, which alone acts on it, and
|
|
164
|
+
each conversation has its own active tab and its own action queue. A conversation's first acting
|
|
165
|
+
call takes the browser's blank start tab if it is free, else opens a new tab (never another
|
|
166
|
+
unowned page); `tabs list`, `adopt`, `wait` and the handoff bookkeeping never open one. When a
|
|
167
|
+
conversation loses its active tab, the tab it gained last becomes active. A popup belongs to the
|
|
168
|
+
owner of the page that opened it. `switch` and `close` take only the conversation's own tabs.
|
|
169
|
+
- **Seen per task tree.** A conversation and its sub-agent conversations form a tree whose root is
|
|
170
|
+
the conversation the person looks at. `tabs list` shows the conversation's own tabs, then the
|
|
171
|
+
tree's other tabs, then other trees' tabs (titles cut to 120 characters, URLs without query or
|
|
172
|
+
fragment). A panel shows its tree's tabs, grouped per sub-task, and the newest pending handoff of
|
|
173
|
+
the tree; a sub-agent's handoff is answered with Done from the root's panel.
|
|
174
|
+
- **Adopt / Move here.** `browser_tabs` action `adopt` (with `tabId`) moves another conversation's
|
|
175
|
+
tab (or an unowned one) to the calling conversation and makes it its active tab; the previous
|
|
176
|
+
owner's next result says so. The panel's 其他对话 / Other conversations menu does the same with
|
|
177
|
+
移到此对话 / Move here, also while only watching. Refused while the owner is in use (a request in
|
|
178
|
+
flight or a pending handoff, long wait or held dialog).
|
|
179
|
+
- **Caps and eviction.** At most 10 tabs in the browser and 6 per conversation. At the device cap
|
|
180
|
+
the daemon first closes the least recently used tab of a conversation that is not in use and has
|
|
181
|
+
made no request for 5 minutes (its non-active tabs before its active one) and tells that
|
|
182
|
+
conversation; it refuses only when no tab qualifies.
|
|
183
|
+
- **Idle close.** A conversation's tabs close after 15 minutes without a request, without an open
|
|
184
|
+
panel showing it and without a pending park; its per-conversation state goes with them. The
|
|
185
|
+
profile is never touched.
|
|
186
|
+
- **Takeover per device.** While the person controls the browser from any conversation's panel,
|
|
187
|
+
every conversation's agent requests are refused. Afterwards only the conversations whose tabs the
|
|
188
|
+
takeover concerned are told that the user had control.
|
|
64
189
|
|
|
65
190
|
## The panel (`ui-src/panel/`)
|
|
66
191
|
|
|
67
192
|
- Every viewer is the owner's: any non-compact panel is interactive (keys, pointer, Esc) while the
|
|
68
|
-
person holds control, whichever panel took it, and
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
193
|
+
person holds control, whichever panel took it, and may ask for frames up to the full viewport
|
|
194
|
+
then. In the watch state the panel takes no page input (no pointer, keys, address bar,
|
|
195
|
+
navigation or tab open / close; the cursor is the arrow), but a click on a tab of the strip shows
|
|
196
|
+
that tab, and 其他对话 / Other conversations › 移到此对话 / Move here moves another conversation's
|
|
197
|
+
tab here. Nothing is kept in storage (the sandboxed iframe has none);
|
|
198
|
+
a remount rebuilds from the daemon's first state. Take over is offered only in the live view;
|
|
199
|
+
handing back with a pending handoff answers it Done.
|
|
200
|
+
- The strip shows the conversation tree's tabs: this conversation's first, then one 子任务 /
|
|
201
|
+
Sub-task group per sub-agent conversation. With no tab in the tree while the browser runs, the
|
|
202
|
+
panel shows 智能体尚未在此对话中打开网页 / "The agent has not opened a page in this conversation
|
|
203
|
+
yet" (never another conversation's page). A refused Move here shows a short line (the tab is in
|
|
204
|
+
use, or this conversation has its most tabs). The banner shows the tree's newest pending handoff;
|
|
205
|
+
its Done / Cancel answer that handoff's conversation.
|
|
206
|
+
- Takeover input (`ui-src/panel/input.ts`): button and wheel events at once, moves coalesced to the
|
|
207
|
+
newest position at most every 33 ms (hover effects, menus and tooltips render in the stream), a
|
|
208
|
+
drag reported until the button is released wherever that happens; the page's cursor from the
|
|
209
|
+
daemon on the picture (known keywords only); a press indicator at the pointer from mousedown until
|
|
210
|
+
the first frame after the release (1 s at most). A visually hidden textarea holds the focus while
|
|
211
|
+
driving: keys go as `down` / `up` (Esc hands back), IME composition (Chinese input) as one `char`
|
|
212
|
+
at `compositionend`, paste as `char` with the clipboard text (Cmd/Ctrl+V itself is not sent;
|
|
213
|
+
text is cut at 10 000 code points). Losing the window or the focus sends `up` for held keys and
|
|
214
|
+
the held button; the sink gives up the focus when control returns to the agent.
|
|
215
|
+
- Frame size: the picture's CSS box times the device pixel ratio capped at 1.25, within 640 px wide
|
|
216
|
+
in the side view and the full viewport while the person drives; the daemon may send smaller
|
|
217
|
+
frames on a slow link (see the pacing above).
|
|
218
|
+
- 允许 allows the blocked host; while the person drives it then opens the blocked page (the blocked
|
|
219
|
+
navigation, or the page whose resource was refused), again on the next connection if the browser
|
|
220
|
+
restarted, taking over again first (a restarted daemon starts with the agent in control); a hand
|
|
221
|
+
back cancels that reopen. A 4404 after a live view (a restart) is retried twice (1 s, 3 s)
|
|
222
|
+
before "not running"; one before any
|
|
223
|
+
live view is "not running" at once. "Not running" looks for the browser quietly (it stays up
|
|
224
|
+
until the browser answers) every 10 s while visible, for 30 minutes at most (a ticket never
|
|
225
|
+
starts the service). A refused allow or answer shows the kernel's reason.
|
|
226
|
+
- Look (browser panel design 2026-11-25): the host's panel is the one box. The tab strip, toolbar,
|
|
227
|
+
status line and picture are separated by space and ground, not borders. Colours come from the
|
|
228
|
+
host's `--cb-*` tokens (light and dark). Until the browser's state and its first frame are there,
|
|
229
|
+
the whole panel is one skeleton and nothing else; then it switches once to the live panel. "Not
|
|
230
|
+
running", offline and error show at once as the centred idle state alone (no tabs, toolbar or
|
|
231
|
+
status line: nothing to navigate); a browser that comes up switches once to the live panel on
|
|
232
|
+
its first frame. The picture is contained and centred on a neutral ground
|
|
233
|
+
(soft shadow; a 2 px accent ring while the person is in control). The status line has a fixed
|
|
234
|
+
height. Take over is there at every width: below 440 px the tabs and the address merge into one
|
|
235
|
+
button with a tab count, and forward and reload move into a "more" menu. On a phone (a screen
|
|
236
|
+
under 600 px, the host's compact class) the panel only watches. A page that asks for a human check
|
|
237
|
+
(the active tab's `blocker` of kind `verification`, reported by the daemon) shows a warn strip with 去验证 as the one primary
|
|
238
|
+
action.
|
|
239
|
+
- Size: the host fills its panel with the embed in both panel modes. The page posts no `resize`,
|
|
240
|
+
and the viewer's frame size follows the shown size. The page asks for full mode with `panel-mode`
|
|
241
|
+
on take over, and for the side panel on hand back (here, or when control returns to the agent
|
|
242
|
+
elsewhere). Its layout follows only the host's `panel-mode` (sent after `init` and on every
|
|
243
|
+
change). The host keeps the frame mounted across the switch, so the viewer connection survives it.
|
|
77
244
|
- A dialog strip hides after 10 s or when the page changes; agent clicks flash once each; a lock
|
|
78
245
|
shows a secure page. The panel listens only to messages from its host page.
|