@capybara-hq/plugin-browser 0.1.0-rc.4 → 0.1.0-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "name": "browser",
4
- "version": "0.1.0-rc.4",
4
+ "version": "0.1.0-rc.6",
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,7 +17,7 @@
17
17
  "entry": "./dist/index.mjs",
18
18
  "manifest": {
19
19
  "name": "browser",
20
- "version": "0.1.0-rc.4",
20
+ "version": "0.1.0-rc.6",
21
21
  "sdk": "^0.1.0-rc.69",
22
22
  "provides": [],
23
23
  "requires": [],
package/README.md CHANGED
@@ -27,7 +27,8 @@ A real browser in the person's device for agents (browser use spec,
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
29
  - `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 (a boolean, not
30
+ then raises an `InputRequired` question `{ done: boolean }` in the conversation, with `open`
31
+ naming the `browser` panel so the person's conversation page opens it (a boolean, not
31
32
  a 完成 / 取消 enum: the kernel's `answerHandoff`, which the banner uses, answers `{ done }`); on
32
33
  resume it clears the notice (with Done also handing the browser back, so a takeover the person
33
34
  still holds ends) and returns the page snapshot, or fails with "The user cancelled the handoff;
@@ -43,14 +44,60 @@ A real browser in the person's device for agents (browser use spec,
43
44
 
44
45
  ## The daemon (`daemon/`)
45
46
 
46
- - Chromium starts on the daemon's first start. A launch that fails (no download, a refused
47
- network) does not stop the daemon: every request answers the cause and launches again. When the
48
- device's proxy refuses Playwright's download hosts (`cdn.playwright.dev`,
49
- `playwright.download.prss.microsoft.com`, `storage.googleapis.com` where the CDN redirects the
50
- headless shell, or `PLAYWRIGHT_DOWNLOAD_HOST`), the reply lists them
51
- as blocked hosts, so the person is asked to allow them. A `PLAYWRIGHT_BROWSERS_PATH` in the
52
- device's environment that already holds this build's headless shell revision is used as is
53
- (a read-only image cache); otherwise the browser is installed into `<state>/browsers`.
47
+ - Chromium starts on the daemon's first start. On Linux devices (device-docker, device-e2b) it is
48
+ the full Chromium build in its new headless mode, so the browser presents as an ordinary Chrome:
49
+ Chrome's own reduced user agent for the platform (`--user-agent`, never "HeadlessChrome"), the
50
+ browser's own client hints, a window the size of the viewport, the device's locale and time zone.
51
+ On macOS (device-local) too where the machine's capybara-device says its sandbox allows it
52
+ (`CAPYBARA_SERVICE_MACH=chromium`, capybara-hq/core#843); the browser gets `MAC_CHROMIUM_TMPDIR`
53
+ and crash reporting off. An older capybara-device keeps the headless shell in one process (and
54
+ nothing larger is downloaded). First start there: one download into the install directory (about 377 MB, 16 s on a fast
55
+ link), one restart, then about 2 s to launch. Nothing spoofs a fingerprint, solves a CAPTCHA or
56
+ hides automation beyond Playwright's own flags (`navigator.webdriver` stays true).
57
+ - Where the browser comes from (plugins#209: never from a place the service or an agent command
58
+ could write once it runs): the provider's install directory `CAPYBARA_SERVICE_INSTALL`
59
+ (device-local) is filled on the first start, sealed with `.sealed`, and the daemon answers
60
+ `restart` and exits, so every later start runs it read only (the plugin starts the service again
61
+ within the same tool call, waiting while `ensureService` still reports the exiting process's
62
+ start time, for at most 30 s; an unsealed directory is always installed afresh, never trusted as
63
+ found); else a `PLAYWRIGHT_BROWSERS_PATH` the daemon cannot write, outside the workspace
64
+ (device-docker / device-e2b ship it in `/opt/capybara-browsers`, pinned to this package's
65
+ playwright-core): this build's revision, else the newest revision of the build there. Nothing
66
+ else: without such a place the browser does not start and says how to get one (update
67
+ capybara-device; recreate a cloud device on the current image). It never installs where it
68
+ could rewrite the browser itself.
69
+ - Uploads are read by the daemon (opened without following a final link, accepted only when the
70
+ resolved path lies in the workspace and names the very file opened) and handed to Chromium from
71
+ memory, at most 50 MiB; downloads are copied from Playwright's private file into an exclusively
72
+ created file in `<workspace>/downloads`, checked to be that directory's own before any byte is
73
+ written. So a link the agent plants in the workspace never makes the service read or write its
74
+ own profile.
75
+ - The network: Chromium sends everything, loopback included, through the device's proxy
76
+ (`HTTPS_PROXY` / `HTTP_PROXY` of the service, the same proxy and rules as the device's commands:
77
+ the proxy resolves the name, with the fake-IP DNS fallback, and judges the address). A proxy URL
78
+ with credentials goes to Playwright's `proxy` option, which answers the challenge by
79
+ intercepting requests; under that interception Chromium loses a request it restarts for an
80
+ ACCEPT_CH frame (www.google.com sends one), so the daemon disables `AcceptCHFrame` (its
81
+ `--disable-features` repeats Playwright's own list: Chromium takes only the last flag), and
82
+ `--disable-auto-reload` keeps a network error page from reloading itself (that reload aborted
83
+ the agent's next navigation in the tab).
84
+ - A navigation that fails says why (`unreachable`): Chromium's net error with its meaning, and
85
+ for a failed tunnel what the device's proxy answers for the host (refused by the network
86
+ settings: `blocked`; could not connect: the name did not resolve, or the host refused or did not
87
+ answer). A navigation with no page within 30 s is stopped (CDP `Page.stopLoading`: one left in
88
+ flight keeps the page's queries waiting), so the tab shows its previous page and the next
89
+ request works on it. A 204 / 205 answer says so. The tab list runs beside the actions, and a
90
+ reply's title and verification check are bounded (2 s), so neither waits on a hanging page.
91
+ - A launch that fails (no download, a refused network) does not stop the daemon: every request
92
+ answers the cause and launches again. When the device's proxy refuses Playwright's download
93
+ hosts (`cdn.playwright.dev`, `playwright.download.prss.microsoft.com`, `storage.googleapis.com`
94
+ where the CDN redirects the download, or `PLAYWRIGHT_DOWNLOAD_HOST`), the reply lists them as
95
+ blocked hosts, so the person is asked to allow them.
96
+ - Verification pages (bot checks, CAPTCHAs: recognised by URL, title, a visible CAPTCHA widget,
97
+ or a 418 / 429 document): every tool result while one shows starts with a note telling the agent
98
+ to call `browser_handoff` instead of solving it or switching sites, and the viewer's tab state
99
+ carries `blocker: { kind: "verification", url }` on that tab (cleared when its page changes) for
100
+ the panel's "需要你完成验证" strip.
54
101
  - The daemon stops after 15 minutes without requests and viewers. A pending handoff keeps it
55
102
  running for up to 24 hours after its notice (the person may take a while to sign in); the
56
103
  device's own idle suspension can still stop it sooner, and then the question stays open in the
@@ -59,28 +106,88 @@ A real browser in the person's device for agents (browser use spec,
59
106
  10 minutes of the last write (a provider that restarts the service for a network change, see
60
107
  device-local) reopens them; an idle stop removes the file. The profile keeps cookies and storage
61
108
  on its own.
109
+ - `<state>/cookies.json` holds the persistent cookies from the moment a stop begins until the next
110
+ start has merged the ones the profile lacks (then it is removed, so a logout while the browser
111
+ ran is never undone by an old file). It exists because the service's kill (2 s after SIGTERM)
112
+ can land while a loaded Chromium is still writing its Cookies file. It lives in the service
113
+ state directory, outside every workspace and project (core `packages/device`), mode 0600, and
114
+ holds what Chromium's own `profile/Default/Cookies` holds there. That file is not protected
115
+ either: the daemon runs Chromium with `--use-mock-keychain`, so its values are only obfuscated
116
+ with a key every Chromium shares (observed: `encrypted_value` of 51 bytes, readable by anyone
117
+ who can read the directory). The JSON therefore adds no exposure.
62
118
  - A `handoff_clear` with `handback` (the person answered Done) also ends a takeover. Dropping a
63
119
  handoff on the next agent request is device-wide: every conversation of the device is the
64
120
  owner's.
121
+ - Viewer input (mouse, keys, text, address bar, tabs) is applied only while the person holds
122
+ control: a viewer in the watch state is read-only and its input is dropped on arrival, and input
123
+ still queued when control returns to the agent is dropped too (input already running, a navigation
124
+ or a long paste, finishes). Keys and buttons the person still holds are released when control
125
+ returns to the agent or the viewer ends, each on the tab where it was pressed (a held button after
126
+ moving the pointer outside the viewport, so the release completes no click), so the agent never
127
+ inherits a held Shift or a drag. Mouse moves are coalesced (the newest position wins while one
128
+ waits). After a move, click or scroll the daemon answers the page's cursor under the pointer
129
+ (`cursor`, only when it changed), off the input queue (the newest position wins, one lookup at a
130
+ time, an answer later than 200 ms is dropped) and without page code: CDP hit-tests the point
131
+ (`DOM.getNodeForLocation`, through shadow roots and in-process frames) and a function in an
132
+ isolated world reads the computed `cursor`, resolving `auto` as Chromium does (an I-beam over
133
+ editable fields and text); `pointer-events: none` elements are skipped as Chromium does;
134
+ out-of-process frames are entered through their own session (at most 20 frames looked at, 3
135
+ levels, matched in the page's coordinates), detached with their frame or when the viewer leaves
136
+ the page.
137
+ - Frames are binary messages (`encodeFrame`: tag, seq, width, height, JPEG); every other message is
138
+ JSON. Pacing (`daemon/viewer-pacing.ts`): the daemon pings each viewer every second (the path's
139
+ own round trip) and compares each frame's ack round trip with it. While frames take longer than
140
+ 120 ms over it (a click would wait that long behind them on the slowest hop), it lowers the JPEG
141
+ quality (60, 45, 35, 25) and then the scale (down to half), allows only one frame in flight, and
142
+ steps back up after six quick frames. At most 15 frames per second; only the newest frame waits
143
+ (a stale one is replaced), and Chromium encodes the next frame at most every 500 ms while one
144
+ waits. JSON messages (state, cursor, pings, dialogs) never wait behind a held frame.
65
145
 
66
146
  ## The panel (`ui-src/panel/`)
67
147
 
68
148
  - Every viewer is the owner's: any non-compact panel is interactive (keys, pointer, Esc) while the
69
- person holds control, whichever panel took it, and asks for full-viewport frames then. Nothing
70
- is kept in storage (the sandboxed iframe has none); a remount rebuilds from the daemon's first
71
- state. Take over is offered only in the live view; handing back with a pending handoff answers
72
- it Done.
73
- - 允许 allows the blocked host, then opens the blocked page (the blocked navigation, or the page
74
- whose resource was refused), again on the next connection if the browser restarted. A 4404
75
- after a live view (a restart) is retried twice (1 s, 3 s) before "not running"; one before any
149
+ person holds control, whichever panel took it, and may ask for frames up to the full viewport
150
+ then. In the watch state the panel is read-only (no pointer, keys, address bar, tabs or
151
+ navigation; the cursor is the arrow). Nothing is kept in storage (the sandboxed iframe has none);
152
+ a remount rebuilds from the daemon's first state. Take over is offered only in the live view;
153
+ handing back with a pending handoff answers it Done.
154
+ - Takeover input (`ui-src/panel/input.ts`): button and wheel events at once, moves coalesced to the
155
+ newest position at most every 33 ms (hover effects, menus and tooltips render in the stream), a
156
+ drag reported until the button is released wherever that happens; the page's cursor from the
157
+ daemon on the picture (known keywords only); a press indicator at the pointer from mousedown until
158
+ the first frame after the release (1 s at most). A visually hidden textarea holds the focus while
159
+ driving: keys go as `down` / `up` (Esc hands back), IME composition (Chinese input) as one `char`
160
+ at `compositionend`, paste as `char` with the clipboard text (Cmd/Ctrl+V itself is not sent;
161
+ text is cut at 10 000 code points). Losing the window or the focus sends `up` for held keys and
162
+ the held button; the sink gives up the focus when control returns to the agent.
163
+ - Frame size: the picture's CSS box times the device pixel ratio capped at 1.25, within 640 px wide
164
+ in the side view and the full viewport while the person drives; the daemon may send smaller
165
+ frames on a slow link (see the pacing above).
166
+ - 允许 allows the blocked host; while the person drives it then opens the blocked page (the blocked
167
+ navigation, or the page whose resource was refused), again on the next connection if the browser
168
+ restarted, taking over again first (a restarted daemon starts with the agent in control); a hand
169
+ back cancels that reopen. A 4404 after a live view (a restart) is retried twice (1 s, 3 s)
170
+ before "not running"; one before any
76
171
  live view is "not running" at once. "Not running" looks for the browser quietly (it stays up
77
172
  until the browser answers) every 10 s while visible, for 30 minutes at most (a ticket never
78
173
  starts the service). A refused allow or answer shows the kernel's reason.
79
- - Size: in the side panel the page posts the embed `resize` (120–4000) for the 16:10 frame at the
80
- available width plus its bars, again whenever its box changes; in full mode (asked for with
81
- `panel-mode` on take over) the host fills the panel and the frame is letterboxed in it, with
82
- the viewer's frame size following the shown size. The host sends no mode back, so full mode
83
- ends with the person's control by any path (hand back here or elsewhere, the agent resuming),
84
- and the side size is asked for again.
174
+ - Look (browser panel design 2026-11-25): the host's panel is the one box. The tab strip, toolbar,
175
+ status line and picture are separated by space and ground, not borders. Colours come from the
176
+ host's `--cb-*` tokens (light and dark). Until the browser's state and its first frame are there,
177
+ the whole panel is one skeleton and nothing else; then it switches once to the live panel. "Not
178
+ running", offline and error show at once as the centred idle state alone (no tabs, toolbar or
179
+ status line: nothing to navigate); a browser that comes up switches once to the live panel on
180
+ its first frame. The picture is contained and centred on a neutral ground
181
+ (soft shadow; a 2 px accent ring while the person is in control). The status line has a fixed
182
+ height. Take over is there at every width: below 440 px the tabs and the address merge into one
183
+ button with a tab count, and forward and reload move into a "more" menu. On a phone (a screen
184
+ under 600 px, the host's compact class) the panel only watches. A page that asks for a human check
185
+ (the active tab's `blocker` of kind `verification`, reported by the daemon) shows a warn strip with 去验证 as the one primary
186
+ action.
187
+ - Size: the host fills its panel with the embed in both panel modes. The page posts no `resize`,
188
+ and the viewer's frame size follows the shown size. The page asks for full mode with `panel-mode`
189
+ on take over, and for the side panel on hand back (here, or when control returns to the agent
190
+ elsewhere). Its layout follows only the host's `panel-mode` (sent after `init` and on every
191
+ change). The host keeps the frame mounted across the switch, so the viewer connection survives it.
85
192
  - A dialog strip hides after 10 s or when the page changes; agent clicks flash once each; a lock
86
193
  shows a secure page. The panel listens only to messages from its host page.