dsh-embedded-browser-next 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.en.md +275 -0
- package/README.md +274 -2
- package/cordis.patch.yml +16 -0
- package/lib/browser.js +2634 -0
- package/lib/cdp.js +320 -0
- package/lib/client.js +3991 -0
- package/lib/diagnostics.js +48 -0
- package/lib/downloads.js +73 -0
- package/lib/external.js +96 -0
- package/lib/human.js +145 -0
- package/lib/index.js +609 -0
- package/lib/lazy.js +193 -0
- package/lib/mjpeg.js +154 -0
- package/lib/paths.js +107 -0
- package/lib/residency.js +234 -0
- package/lib/router.js +687 -0
- package/lib/routes.js +446 -0
- package/lib/screencast.js +1629 -0
- package/lib/snapshot-window.js +73 -0
- package/lib/tools.js +740 -0
- package/lib/ws.js +253 -0
- package/package.json +60 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 roc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# dsh-embedded-browser-next
|
|
2
|
+
|
|
3
|
+
[简体中文](README.md) | **English**
|
|
4
|
+
|
|
5
|
+
> **Transparency note: this fork is AI-maintained.**
|
|
6
|
+
>
|
|
7
|
+
> Upstream [`imroc/dsh-embedded-browser`](https://github.com/imroc/dsh-embedded-browser) stopped at `0.3.0` (published 2026-09-21, last commit 2026-09-23), leaving five open issues and pull requests unanswered. **`dsh-embedded-browser-next`** picks up where it left off and evolves the plugin for modern DeepSeek Harness (DSH) builds. It ships under its own package name, **`dsh-embedded-browser-next`**, installable from npm and China npm mirrors; the browser data directory keeps the old path (`$DSH_HOME/embedded-browser/profile`), so existing logins survive. **If you previously installed the original `dsh-embedded-browser` 0.3.0, uninstall it first**, otherwise both plugin rows would coexist.
|
|
8
|
+
>
|
|
9
|
+
> **Every change since the fork has been produced by AI models under human direction (`LXYCWDMGS`)** — code and engineering by **DeepSeek V4.1 Flash**, documentation and audit review by **Gemini 4 Neon**. The human sets direction, reviews results, and makes every release call. You have the right to know that before installing.
|
|
10
|
+
>
|
|
11
|
+
> Original author: **roc <i@roc.im>** (MIT; original copyright preserved in [`LICENSE`](LICENSE)). Full history since the fork is recorded in [`CHANGELOG.md`](CHANGELOG.md). This fork is neither endorsed by nor affiliated with the original author.
|
|
12
|
+
|
|
13
|
+
A browser that lives inside your DSH host: **every DSH session gets its own tab**, the AI drives it with 26 `browser_embedded_*` tools, and you watch — or take over — that same page from an **on-demand right-Sidebar tab**, a **floating panel**, or a **real browser window**.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Quick Install
|
|
18
|
+
|
|
19
|
+
**Requirements:** DSH Desktop `>= 0.1.5-rc.2`, Node.js `>= 22.19`, and a Chromium-based browser (Chrome / Edge / Chromium, auto-detected, no build step).
|
|
20
|
+
|
|
21
|
+
### Option 1: DSH Desktop UI (Recommended)
|
|
22
|
+
|
|
23
|
+
1. Open DSH Desktop → **Plugins** → **Add Plugin**;
|
|
24
|
+
2. Make sure the install source is the **China mainland mirror** (fastest locally, no proxy needed);
|
|
25
|
+
3. Enter the package name and confirm:
|
|
26
|
+
```text
|
|
27
|
+
dsh-embedded-browser-next
|
|
28
|
+
```
|
|
29
|
+
4. **Fully quit DSH Desktop (including the system tray icon) and relaunch** so the plugin loads.
|
|
30
|
+
|
|
31
|
+
### Option 2: DSH CLI
|
|
32
|
+
|
|
33
|
+
> The `desktop` profile is managed exclusively by the desktop app and the CLI refuses it outright, so desktop users should use Option 1. The command below applies to other profiles such as `web`.
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
# A non-desktop profile (replace `web` with the profile you actually use)
|
|
37
|
+
dsh plugin --profile web add dsh-embedded-browser-next
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Option 3: GitHub direct / offline tarball (fallback)
|
|
41
|
+
|
|
42
|
+
> The GitHub link does **not** go through the China mirror and needs a proxy; without one, download the `.tgz` and install from a local path.
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
# With a proxy: install straight from the GitHub repository
|
|
46
|
+
dsh plugin --profile web add github:LXYCWDMGS/dsh-embedded-browser-next
|
|
47
|
+
|
|
48
|
+
# Without one: download dsh-embedded-browser-next-1.0.0.tgz from Releases first, then:
|
|
49
|
+
dsh plugin --profile web add ./dsh-embedded-browser-next-1.0.0.tgz
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
> Release tarballs: [Releases](https://github.com/LXYCWDMGS/dsh-embedded-browser-next/releases) (`v1.0.0`). Fully restart DSH Desktop after installing.
|
|
53
|
+
> **Upgrading from `<= 0.2.0` (`dsh-browser-panel`)?** Point `profileDir` at `$DSH_HOME/browser-panel/profile` to keep existing logins.
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Why This Exists
|
|
58
|
+
|
|
59
|
+
- **No GUI on agent hosts:** Containers, VMs, and CI machines have no display to show a login screen.
|
|
60
|
+
- **Headless automation hits human walls:** SSO redirects, QR-code logins, SMS/TOTP codes, CAPTCHAs, and WebAuthn cannot be scripted away.
|
|
61
|
+
- **Cookie exports are brittle:** Copying cookies or `storageState` breaks on device-bound credentials, fingerprints, and session rotation.
|
|
62
|
+
|
|
63
|
+
With `dsh-embedded-browser-next`, you complete the human step right inside the DSH Web UI (or a real window managed by the plugin) on the exact page the AI is working on, then hand control back with one click.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Three Surfaces, One Page
|
|
68
|
+
|
|
69
|
+
The same page can live on three visible surfaces (plus `headless` in the background). The AI always knows where the page is: `browser_embedded_status` reports `layer`, and whenever the surface changes, the next tool result includes `layerChanged` (e.g. `sidebar → float`) and a short explanation.
|
|
70
|
+
|
|
71
|
+
| Layer | Where it lives | Visibility & reclaim | Best for |
|
|
72
|
+
|---|---|---|---|
|
|
73
|
+
| `sidebar` | Right-Sidebar tab (default) | Hidden when switching conversations; idle real browsers reclaim after `reclaimIdleMinutes` | Day-to-day browsing alongside chat |
|
|
74
|
+
| `float` | Floating panel inside the DSH window (**Float / 浮窗**) | Hidden when switching conversations (lives in the same per-session subtree) | Resizing, moving aside, or freeing the sidebar |
|
|
75
|
+
| `window` | Real, separate browser window (**Window / 独立窗口**, `mode: headed`) | Survives conversation switches; governed by whole-browser `idleShutdownMinutes` | Multi-monitor use, cross-origin iframes, persistent logins |
|
|
76
|
+
| `headless` | Background host Chrome (no visible panel) | Governed by `idleShutdownMinutes` | Unattended automation when nobody is watching |
|
|
77
|
+
|
|
78
|
+
### Login durability across surfaces
|
|
79
|
+
|
|
80
|
+
- **Host Chrome (`headless` and `window`):** Uses a persistent profile on disk (`$DSH_HOME/embedded-browser/profile`). All sessions share this profile, and logins survive restarts.
|
|
81
|
+
- **Native Sidebar panel (`sidebar` and `float`):** Runs in a DSH-issued **process-lifetime** webview partition (`dsh-sidebar-browser-*`). Logins stay alive while the app is open, and are cleared when the desktop app quits. Use **Window / 独立窗口** (or `browser_embedded_present({ mode: "window" })`) when you want logins persisted across restarts.
|
|
82
|
+
|
|
83
|
+
### Moving between surfaces
|
|
84
|
+
|
|
85
|
+
- The AI can move the page via `browser_embedded_present({ mode: "sidebar" | "float" | "window" })` without reloading the tab (subject to your `aiPresent*` settings).
|
|
86
|
+
- **Returning from `window` to the panel:** Because the panel and the standalone window are separate browser processes, clicking **Float / 浮窗** or **Back to panel / 回到面板** (or calling `present({ mode: "sidebar" | "float" })`) reads the window's current URL, closes the window back to headless (keeping the profile and logins intact), hands routing back to the panel, and reopens that URL in the panel (`restored: true`). Manually closing the real window also preserves URLs and falls back to headless (up to 8 sessions).
|
|
87
|
+
- **Why there is no in-app cross-conversation watch window:** Everything rendered inside the DSH UI belongs to a per-session subtree that hides on conversation switch. A pixel-stream watch window was tested earlier and removed because native-panel mode emits no pixel stream; `window` is the clean cross-conversation surface.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Architecture
|
|
92
|
+
|
|
93
|
+
```text
|
|
94
|
+
AI Turn (26 browser_embedded_* tools)
|
|
95
|
+
└── Router (lib/router.js)
|
|
96
|
+
├── Native Panel active ──► Right-Sidebar Tab / Float (lib/client.js) ◄── Human (mouse / keyboard / IME)
|
|
97
|
+
└── Headless / Window ──► Host Chrome via CDP (lib/browser.js)
|
|
98
|
+
├── Persistent profile ($DSH_HOME/embedded-browser/profile)
|
|
99
|
+
└── Fallback stream hub (lib/screencast.js ◄──► Panel WebSocket / MJPEG)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
- **Per-session isolation, shared identity:** Every session gets its own tab (created lazily on first tool call or manual panel open). Tools never take a `sessionId` parameter — each handler reads `exec.agent.id` from the execution context, so one session can never steer another session's tab.
|
|
103
|
+
- **Same-origin authentication:** All HTTP routes (`/api/dsh-embedded-browser/state`, `/open`, `/close`, `/open-window`, `/restore-panel`, `/open-external`, `/settings`, `/mjpeg`, `/sessions`, `/health`, `/debug`, `/human-done`) and `/stream` WebSocket upgrades sit behind DSH's own Web UI session auth (`connection.requestRejection`). No extra port, token, or tunnel.
|
|
104
|
+
- **Native panel + headless/window fallback:** On desktop/web UI with native guest support (`realBrowser: on-demand` by default), the AI routes tool calls directly to the visible panel you are looking at so both of you operate the exact same DOM. When the panel is closed, off, or promoted to `window`, routing seamlessly targets the host Chrome over CDP.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Tools (26 Total)
|
|
109
|
+
|
|
110
|
+
By default (`lazyTools: false`), all 26 `browser_embedded_*` tools register at plugin load. Set `lazyTools: true` if you want to keep their schemas off the prompt until the `browser-use` skill is invoked (or `/browser-use` is typed).
|
|
111
|
+
|
|
112
|
+
| Category | Tool | What it does |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| **Observe** | `browser_embedded_status` | Running state, current tab URL/title, active `layer` (`sidebar`/`float`/`window`/`headless`), `layerChanged`, pending human action |
|
|
115
|
+
| | `browser_embedded_page_info` | Lightweight state: URL, title, `readyState`, viewport, scroll offsets, coarse CAPTCHA signal |
|
|
116
|
+
| | `browser_embedded_snapshot` | Title, URL, adaptive numbered inventory of interactive elements (with stable `loc` & `offset` paging), iframe list, visible text |
|
|
117
|
+
| | `browser_embedded_read_element` | Read one element by CSS selector (`text`, `html`, `value`, `attribute`, `visible`, `enabled`, `count`) |
|
|
118
|
+
| | `browser_embedded_js` | Evaluate a JS expression in the page (JSON-serializable result; awaits promises by default) |
|
|
119
|
+
| | `browser_embedded_screenshot` | Capture viewport, `fullPage`, or a `selector` clip as a PNG image attachment (falls back to OS temp dir if attachments are unavailable) |
|
|
120
|
+
| | `browser_embedded_wait` | Wait for `selector`, `url`, `function`, `load`, or `delay` instead of fixed sleeps |
|
|
121
|
+
| **Navigate & Frames** | `browser_embedded_navigate` | Open an `http(s)` URL (starts browser on first use; `newTab` replaces the session's tab) |
|
|
122
|
+
| | `browser_embedded_tab` | `list` all page targets, `switch` this session to another tab, or `close` a tab |
|
|
123
|
+
| | `browser_embedded_frame` | `op=open` opens a cross-origin iframe's URL as the top document to read/interact (destructive to parent page state); `op=back` reloads the original URL |
|
|
124
|
+
| **Act** | `browser_embedded_click` | Click by snapshot `index`, CSS `selector`, visible `text` (semantic controls first, then clickable non-semantic elements like `<span>`/`<div>`; refuses to blind-click plain text and returns its selector), or `x`/`y` viewport coordinates (for cross-origin iframes); supports `double` |
|
|
125
|
+
| | `browser_embedded_type` | Click-focus and type text (React/Vue compatible; `submit: true` presses Enter); supports `index`, `selector`, or `x`/`y` |
|
|
126
|
+
| | `browser_embedded_fill` | Replace an input's value outright via the native setter (React/Vue compatible) |
|
|
127
|
+
| | `browser_embedded_press` | Press a single key (`Enter`, `Tab`, `Escape`, `Backspace`, `Delete`, arrows, `Home`, `End`, `PageUp`/`Down`, `Space`) |
|
|
128
|
+
| | `browser_embedded_hover` | Move pointer over an element (or `x`/`y`) — required for CSS `:hover` menus |
|
|
129
|
+
| | `browser_embedded_select` | Select an option in a native `<select>` by value or visible label |
|
|
130
|
+
| | `browser_embedded_check` | Idempotently check or uncheck a checkbox/radio |
|
|
131
|
+
| | `browser_embedded_scroll` | Scroll `down`, `up`, `left`, `right`, `top`, or `bottom` (optional `pixels`) |
|
|
132
|
+
| | `browser_embedded_drag` | Drag one element onto another (real pointer path, or synthesized drag events for `draggable` elements in the panel) |
|
|
133
|
+
| **Files & Network** | `browser_embedded_upload` | Attach local file(s) to `<input type="file">` without a picker (blocks sensitive credential & OS system directories) |
|
|
134
|
+
| | `browser_embedded_download` | Set download directory or fetch a URL with page cookies into `~/Downloads/dsh-embedded-browser` (paths outside are refused) |
|
|
135
|
+
| | `browser_embedded_http` | `fetch` from inside the page carrying the profile's cookies (bound by page CORS; capped by `maxBytes`) |
|
|
136
|
+
| | `browser_embedded_dialog` | Accept or dismiss blocking `alert` / `confirm` / `prompt` dialogs |
|
|
137
|
+
| **Surface & Human** | `browser_embedded_present` | Move the page between `sidebar`, `float`, and `window` (governed by `aiPresent*` settings) |
|
|
138
|
+
| | `browser_embedded_ask_human` | Bring up this session's browser tab with an instruction banner and wait until the human clicks **Done / 我已完成** |
|
|
139
|
+
| | `browser_embedded_close` | Close this session's tab and free memory (keeps the shared profile and logins) |
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Sidebar Panel Controls
|
|
144
|
+
|
|
145
|
+
- **On-demand tab:** The **Browser / 浏览器** tab opens automatically when a session starts using the browser; conversations that never touch the browser show no extra tab. You can also open it manually from the right-Sidebar guide page.
|
|
146
|
+
- **Toolbar:** Back / Forward / Reload / Repaint, keyboard helpers (`Tab` / `⇧Tab` / `Enter`), **Window / 独立窗口** (promote to the plugin's real Chromium window with persistent profile), **Float / 浮窗** (pop out inside DSH; toggles to **Dock / 收回** while floating), **Settings / 设置** (adjust residency & idle shutdown live), and **Close tab / 结束并清理**.
|
|
147
|
+
- **Hand-over banner:** Appears only in the requesting session's tab with a **Done / 我已完成** button (plus an optional note back to the AI). A small dot on the tab chip signals a pending human request.
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Browser Detection & Optional Lazy Tools
|
|
152
|
+
|
|
153
|
+
- **Auto-detection order:** `browserPath` config → `google-chrome-stable` / `google-chrome` / `chromium` / `chromium-browser` / `chrome` on `PATH` → Playwright cache → Puppeteer cache.
|
|
154
|
+
- **Headed mode:** On **Windows and macOS**, `mode: headed` opens a real browser window directly (no Xvfb needed). On **Linux**, `Xvfb` on `PATH` is optional (falls back to `--headless=new` when absent).
|
|
155
|
+
- **Optional `lazyTools: true`:** By default (`false`), all 26 tools are ready immediately with no skill required. Set `lazyTools: true` to save prompt tokens on non-browser turns, then invoke the `browser-use` skill (or type `/browser-use`) to unlock them (`SKILL_NAME` in `lib/lazy.js`).
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Quick Verification
|
|
160
|
+
|
|
161
|
+
1. Ask the AI to open a page:
|
|
162
|
+
```text
|
|
163
|
+
Use browser_embedded_navigate to open https://example.com, then call browser_embedded_snapshot.
|
|
164
|
+
```
|
|
165
|
+
(If you enabled `lazyTools: true`, invoke the `browser-use` skill or type `/browser-use` first.)
|
|
166
|
+
2. The **Browser / 浏览器** tab appears in the right sidebar automatically.
|
|
167
|
+
3. Test human hand-over:
|
|
168
|
+
```text
|
|
169
|
+
Call browser_embedded_ask_human with "Please complete login in the panel, then click Done."
|
|
170
|
+
```
|
|
171
|
+
Click **Done / 我已完成** — the tool call returns immediately and the AI continues on the authenticated page.
|
|
172
|
+
4. Open a second session and navigate — in host Chrome (`headless` / `window`), it shares the same persistent profile so logins carry over.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Configuration
|
|
177
|
+
|
|
178
|
+
Override fields in your `cordis.patch.yml` (the `config` object is replaced as a whole, so include every key you customize):
|
|
179
|
+
|
|
180
|
+
```yaml
|
|
181
|
+
- id: embedded-browser
|
|
182
|
+
config:
|
|
183
|
+
mode: auto # auto | headed | headless
|
|
184
|
+
viewport: 1440x900
|
|
185
|
+
idleShutdownMinutes: 10
|
|
186
|
+
realBrowser: on-demand # on-demand | always | off
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
<details>
|
|
190
|
+
<summary>Full configuration reference (33 keys)</summary>
|
|
191
|
+
|
|
192
|
+
| Key | Default | Description |
|
|
193
|
+
|---|---|---|
|
|
194
|
+
| `browserPath` | `''` | Explicit Chrome/Chromium binary path; empty = auto-detect. |
|
|
195
|
+
| `profileDir` | `''` | Persistent profile directory; empty = `$DSH_HOME/embedded-browser/profile`. |
|
|
196
|
+
| `mode` | `'auto'` | `auto` = Xvfb headed on Linux when available, else headless. On Windows/macOS, `headed` opens a real browser window; `auto` runs headless. |
|
|
197
|
+
| `screen` | `'1440x900x24'` | Virtual display geometry (`WxHxD`) for private Xvfb on Linux. |
|
|
198
|
+
| `windowSize` | `'1440x900'` | Chrome window size in `headed` mode. |
|
|
199
|
+
| `viewport` | `'1440x900'` | Emulated page viewport and panel canvas coordinate space. |
|
|
200
|
+
| `xvfbDisplay` | `':99'` | Preferred X display for private Xvfb (auto-increments if taken). |
|
|
201
|
+
| `port` | `0` | Fixed CDP DevTools port; `0` picks a free port. |
|
|
202
|
+
| `startUrl` | `'about:blank'` | Initial URL of a fresh session tab. |
|
|
203
|
+
| `extraArgs` | `[]` | Extra Chromium command-line flags. |
|
|
204
|
+
| `snapshotMaxChars` | `4000` | Default visible text budget per `browser_embedded_snapshot`. |
|
|
205
|
+
| `maxElements` | `0` | Elements per snapshot; `0` = adaptive (80 floor, 240 cap, character budget, `offset` paging). Set a positive number for a fixed count. |
|
|
206
|
+
| `realBrowser` | `'on-demand'` | Native panel browser policy: `on-demand` (reclaimed when idle), `always` (kept per conversation), or `off` (headless only). |
|
|
207
|
+
| `reclaimIdleMinutes` | `15` | Minutes before an unpinned idle panel browser is reclaimed. |
|
|
208
|
+
| `maxLiveBrowsers` | `3` | Maximum concurrently live panel browsers (`0` = unlimited; LRU evicted first). |
|
|
209
|
+
| `idleShutdownMinutes` | `10` | Minutes before idle host Chrome shuts down (`0` = never). Lossless: tabs reopen at last URL and profile stays intact. Editable live in panel Settings. |
|
|
210
|
+
| `autoStart` | `false` | Launch host Chrome at DSH startup instead of on first tool call. |
|
|
211
|
+
| `lazyTools` | `false` | `false` = register all 26 tools at load; `true` = gate behind the `browser-use` skill. |
|
|
212
|
+
| `aiPresent` | `'allow'` | Allow (`allow`) or refuse (`off`) agent-initiated surface moves (`browser_embedded_present`). |
|
|
213
|
+
| `aiPresentFloat` | `true` | Allow agent to pop the page into a floating panel. |
|
|
214
|
+
| `aiPresentWindow` | `true` | Allow agent to move the page into a real browser window. |
|
|
215
|
+
| `askHumanTimeoutSeconds` | `600` | Default timeout for `browser_embedded_ask_human`. |
|
|
216
|
+
| `startTimeoutMs` | `20000` | DevTools readiness timeout after launching Chrome. |
|
|
217
|
+
| `streamTransport` | `'mjpeg'` | Fallback panel frame transport: `mjpeg` (`<img>` pipeline) or `ws` (canvas rollback). |
|
|
218
|
+
| `screencastQuality` | `'balanced'` | JPEG quality preset: `smooth` (70), `balanced` (85), `sharp` (95). |
|
|
219
|
+
| `screencastMaxWidth` | `0` | Max streamed frame width; `0` derives from `viewport × renderScale`. |
|
|
220
|
+
| `adaptiveStream` | `true` | Lower frame resolution/quality briefly during motion for responsiveness, restore sharpness when still. |
|
|
221
|
+
| `streamFastScale` | `0.55` | Resolution multiplier during motion when `adaptiveStream: true`. |
|
|
222
|
+
| `streamFastQuality` | `50` | JPEG quality during motion when `adaptiveStream: true`. |
|
|
223
|
+
| `renderScale` | `1.5` | Viewport rasterization multiplier (`1` / `1.5` / `2`) for crisp HiDPI rendering (model screenshots remain CSS-sized). |
|
|
224
|
+
| `fitPanelAspect` | `true` | Match viewport aspect ratio to the sidebar panel while keeping configured width. |
|
|
225
|
+
| `maxViewportHeight` | `1000` | Height cap when `fitPanelAspect: true` (prevents infinite-scroll feeds from stalling). |
|
|
226
|
+
| `pollFrameMs` | `140` | Poll interval (ms, min `60`) for background sessions not holding the active screencast. |
|
|
227
|
+
|
|
228
|
+
</details>
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Security Notes
|
|
233
|
+
|
|
234
|
+
- **Shared Web UI authentication:** Panel HTTP/WS endpoints use DSH's own session auth. Anyone with Web UI access can drive the host browser.
|
|
235
|
+
- **Shared profile scope:** Sessions are isolated in page state, not identity — every session using host Chrome shares the same cookies and logins. Keep `$DSH_HOME/embedded-browser/profile` private and never commit it.
|
|
236
|
+
- **Path fences:**
|
|
237
|
+
- `browser_embedded_upload` blocks sensitive credential directories (`~/.ssh`, `~/.dsh`, `~/.gemini`, `~/.gnupg`, `~/.aws`, `~/.kube`, `~/.docker`) and OS system roots.
|
|
238
|
+
- `browser_embedded_download` restricts `downloadPath` to `~/Downloads/dsh-embedded-browser` (anything outside is refused).
|
|
239
|
+
- External URL opening on Windows uses `rundll32.exe url.dll,FileProtocolHandler` with direct argv (no `cmd.exe` shell interpolation).
|
|
240
|
+
- **Non-root Chrome:** Run as a non-root user to keep Chromium's sandbox enabled; `--no-sandbox` is only added automatically when running as root.
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Troubleshooting
|
|
245
|
+
|
|
246
|
+
- **Browser not found:** Set `browserPath` in `cordis.patch.yml` to your local Chrome / Edge / Chromium executable.
|
|
247
|
+
- **Corrupted profile or reset logins:** Stop DSH, delete `$DSH_HOME/embedded-browser/profile`, and restart DSH (a clean profile is recreated on next use).
|
|
248
|
+
- **Check logs:** Diagnostic logs are written under `$DSH_HOME/logs/` (`browser-boot.log`, `browser-import.log`, `browser-stream.log`, `panel-trace.log`).
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Rollback
|
|
253
|
+
|
|
254
|
+
```sh
|
|
255
|
+
dsh plugin --profile desktop remove dsh-embedded-browser-next
|
|
256
|
+
# or uninstall directly from DSH Desktop → Plugins, then fully restart DSH Desktop
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Your profile directory (`$DSH_HOME/embedded-browser/profile`) is preserved across uninstall; delete it manually if you want to wipe saved logins.
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Development & Testing
|
|
264
|
+
|
|
265
|
+
```sh
|
|
266
|
+
npm test # runs all 37 unit test files (320 tests)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Logs are written under `$DSH_HOME/logs/` (`browser-boot.log`, `browser-import.log`, `browser-stream.log`, `panel-trace.log`). Set `DSH_BROWSER_TRACE=off` to silence panel traces.
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT
|
package/README.md
CHANGED
|
@@ -1,3 +1,275 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-embedded-browser-next
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**简体中文** | [English](README.en.md)
|
|
4
|
+
|
|
5
|
+
> **先读这一段:这个接续维护版由 AI 协作维护。**
|
|
6
|
+
>
|
|
7
|
+
> 上游 [`imroc/dsh-embedded-browser`](https://github.com/imroc/dsh-embedded-browser) 停更在 `0.3.0`(2026-09-21 发布,最后一次提交 2026-09-23),遗留的 5 个 issue 与 PR 均无回复。**`dsh-embedded-browser-next`** 是它的持续进化版,面向最新 DeepSeek Harness(DSH)长期迭代。包名独立为 **`dsh-embedded-browser-next`**,可直接从 npm 与国内镜像源安装;浏览器数据目录沿用旧路径(`$DSH_HOME/embedded-browser/profile`),登录态不受影响。**若此前装过原作者旧版 `dsh-embedded-browser` 0.3.0,请先卸载再安装本包**,避免两个插件同时占位。
|
|
8
|
+
>
|
|
9
|
+
> **自 fork 以来的每一处改动均由 AI 模型在人类(`LXYCWDMGS`)指导下完成**——代码与工程由 **DeepSeek V4.1 Flash** 编写,文档与审计复核由 **Gemini 4 Neon** 负责;人类负责拍板方向、审阅与最终发布决策。你有权在安装前清楚了解这一点。
|
|
10
|
+
>
|
|
11
|
+
> 原作者:**roc <i@roc.im>**(MIT 许可,原始版权声明保留于 [`LICENSE`](LICENSE))。接续之后的完整变更记录见 [`CHANGELOG.md`](CHANGELOG.md)。本仓库不代表原作者立场,也未获其背书。
|
|
12
|
+
|
|
13
|
+
一个住在 DSH 宿主里的浏览器:**每个 DSH 会话拥有独立标签页**,AI 通过 26 个 `browser_embedded_*` 工具驱动页面,而你可以通过**按需弹出的右侧栏 tab**、**窗口内浮窗**或**独立真实浏览器窗口**随时观看和接管同一页。
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 快速安装
|
|
18
|
+
|
|
19
|
+
**环境要求:** DSH 桌面端 `>= 0.1.5-rc.2`、Node.js `>= 22.19`、本机任意 Chromium 系浏览器(Chrome / Edge / Chromium,自动探测,纯 JS 免编译)。
|
|
20
|
+
|
|
21
|
+
### 方式一:DSH 桌面端界面安装(推荐)
|
|
22
|
+
|
|
23
|
+
1. 打开 DSH 桌面端 → 进入 **插件** → 点击 **添加插件**;
|
|
24
|
+
2. 确认安装源为 **「中国大陆镜像源」**(国内直连,无需代理);
|
|
25
|
+
3. 在输入框中直接填包名并确认安装:
|
|
26
|
+
```text
|
|
27
|
+
dsh-embedded-browser-next
|
|
28
|
+
```
|
|
29
|
+
4. 安装完成后,**完整退出 DSH 桌面端(含系统托盘图标)再重新启动**即可生效。
|
|
30
|
+
|
|
31
|
+
### 方式二:CLI 命令行安装
|
|
32
|
+
|
|
33
|
+
> `desktop` profile 由桌面端应用独占管理,CLI 会直接拒绝操作;桌面端用户请走方式一。下面的命令适用于 `web` 等其它 profile。
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
# 非桌面端 profile(把 `web` 换成你的实际 profile 名)
|
|
37
|
+
dsh plugin --profile web add dsh-embedded-browser-next
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### 方式三:GitHub 直链 / 离线包(备选)
|
|
41
|
+
|
|
42
|
+
> GitHub 直链**不走**国内镜像源,需要自备代理;没有代理时建议下载 `.tgz` 后用本地路径安装。
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
# 有代理:直接从 GitHub 仓库安装
|
|
46
|
+
dsh plugin --profile web add github:LXYCWDMGS/dsh-embedded-browser-next
|
|
47
|
+
|
|
48
|
+
# 无代理:先从 Releases 下载 dsh-embedded-browser-next-1.0.0.tgz,再用本地路径安装
|
|
49
|
+
dsh plugin --profile web add ./dsh-embedded-browser-next-1.0.0.tgz
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
> 发布包见 [Releases](https://github.com/LXYCWDMGS/dsh-embedded-browser-next/releases)(`v1.0.0`)。安装后同样需**完整重启 DSH 桌面端**。
|
|
53
|
+
> **从 `<= 0.2.0`(旧名 `dsh-browser-panel`)升级?** 将 `profileDir` 指向 `$DSH_HOME/browser-panel/profile` 即可保留旧版登录态。
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 为什么需要它
|
|
58
|
+
|
|
59
|
+
- **agent 宿主无图形界面**:容器、虚拟机、CI 机器没有显示器,无法向人展示登录页。
|
|
60
|
+
- **纯无头自动化卡在“必须真人介入”的环节**:SSO 跳转、扫码登录、短信/动态验证码、图形验证码、WebAuthn 硬件密钥都无法靠脚本绕过。
|
|
61
|
+
- **导出 cookie 很脆弱**:设备绑定凭据(DBSC)、浏览器指纹、会话轮换都会让搬运 cookie / `storageState` 失效。
|
|
62
|
+
|
|
63
|
+
有了 `dsh-embedded-browser-next`,你可以直接在 DSH Web UI(或插件托管的独立窗口)里帮 AI 完成登录/验证,点一下按钮把已登录的页面无缝交回 AI 继续跑。
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 三个表面,一个页面
|
|
68
|
+
|
|
69
|
+
同一个页面可以在三种可见形态之间切换(另加后台 `headless` 形态)。AI 随时能感知当前所在层:`browser_embedded_status` 返回 `layer`,一旦发生换层,下一次工具结果还会带上 `layerChanged`(如 `sidebar → float`)与一句说明。
|
|
70
|
+
|
|
71
|
+
| 层 | 所在位置 | 可见性与回收规则 | 适用场景 |
|
|
72
|
+
|---|---|---|---|
|
|
73
|
+
| `sidebar` | 右侧栏 tab(默认) | 切换会话即隐藏;未固定的面板浏览器空闲超 `reclaimIdleMinutes` 自动回收 | 日常边聊边看 |
|
|
74
|
+
| `float` | DSH 窗口内的浮动面板(工具栏 **浮窗**) | 切换会话即隐藏(仍属于该会话子树) | 拉大画面、挪开遮挡、腾出右侧栏 |
|
|
75
|
+
| `window` | 独立真实浏览器窗口(工具栏 **独立窗口**,`mode: headed`) | 不受切会话影响;受整机 `idleShutdownMinutes` 闲置钟管理 | 副屏查看、跨域 iframe、需要持久登录态 |
|
|
76
|
+
| `headless` | 后台宿主 Chrome(无界面) | 受整机 `idleShutdownMinutes` 闲置钟管理 | 无人值守的后台自动化 |
|
|
77
|
+
|
|
78
|
+
### 不同表面的登录态持久性
|
|
79
|
+
|
|
80
|
+
- **宿主 Chrome(`headless` 与 `window`)**:使用磁盘上的持久 profile(`$DSH_HOME/embedded-browser/profile`),所有会话共享同一份登录态,**重启后依然保留**。
|
|
81
|
+
- **原生右侧栏面板(`sidebar` 与 `float`)**:运行在 DSH 分配的**进程级临时分区**(`dsh-sidebar-browser-*`)中,应用运行期间登录态有效,**退出桌面端后清空**。需要跨重启保留登录的站点,请使用 **独立窗口**(或 `browser_embedded_present({ mode: "window" })`)。
|
|
82
|
+
|
|
83
|
+
### 换层与收回
|
|
84
|
+
|
|
85
|
+
- AI 可通过 `browser_embedded_present({ mode: "sidebar" | "float" | "window" })` 搬移当前页而不刷新页面(受 `aiPresent*` 配置约束)。
|
|
86
|
+
- **从独立窗口回到面板**:由于面板与独立窗口属于两个不同的浏览器进程,在 `window` 模式下点工具栏「浮窗」或面板提示上的「回到面板」(或 AI 调用 `present({ mode: "sidebar" | "float" })`),宿主会记录窗口当前 URL → 关闭独立窗口并切回无头(profile 与登录态保留)→ 将路由交回面板并按原 URL 重开(返回 `restored: true`)。手动直接关闭独立窗口也会先记录各会话 URL 再回落无头重开(最多 8 个会话)。
|
|
87
|
+
- **为什么没有窗口内“跨会话监视窗”**:DSH 窗口内绘制的一切元素都属于单个会话子树,切会话即隐藏。早期曾试验过像素流监视窗,但原生面板模式无像素流可推,最终撤回;跨会话观看统一走 `window` 独立窗口层。
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 工作原理
|
|
92
|
+
|
|
93
|
+
```text
|
|
94
|
+
AI 回合(26 个 browser_embedded_* 工具)
|
|
95
|
+
└── 路由层(lib/router.js)
|
|
96
|
+
├── 原生面板在线 ──► 右侧栏 tab / 浮窗(lib/client.js)◄── 人类(鼠标 / 键盘 / 输入法)
|
|
97
|
+
└── 无头 / 独立窗 ──► 宿主 Chrome · CDP(lib/browser.js)
|
|
98
|
+
├── 持久 profile($DSH_HOME/embedded-browser/profile)
|
|
99
|
+
└── 回退推流 Hub(lib/screencast.js ◄──► 面板 WebSocket / MJPEG)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
- **按会话隔离页面、共享身份**:标签页在会话首次调用工具或手动打开面板时懒创建。所有工具均不暴露 `sessionId` 参数,统一从执行上下文 `exec.agent.id` 读取,杜绝跨会话误操作。
|
|
103
|
+
- **同源会话鉴权**:所有 HTTP 路由(`/api/dsh-embedded-browser/state`、`/open`、`/close`、`/open-window`、`/restore-panel`、`/open-external`、`/settings`、`/mjpeg`、`/sessions`、`/health`、`/debug`、`/human-done`)与 `/stream` WebSocket 升级均复用 DSH Web UI 原生鉴权(`connection.requestRejection`),无需额外端口、token 或隧道。
|
|
104
|
+
- **原生面板 + 宿主 Chrome 双路路由**:默认开启原生面板浏览器(`realBrowser: on-demand`),当你看着面板时,AI 的工具调用直接路由到你眼前的同一份 DOM;面板关闭、禁用或切到 `window` 层时,自动经 CDP 路由到宿主 Chrome。
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## 工具一览(共 26 个)
|
|
109
|
+
|
|
110
|
+
默认配置下(`lazyTools: false`),全部 26 个 `browser_embedded_*` 工具随插件加载即注册。如需节省非浏览器对话的 prompt token,可设为 `lazyTools: true`,在调用 `browser-use` 技能(或发送 `/browser-use`)后再开闸注册。
|
|
111
|
+
|
|
112
|
+
| 分类 | 工具 | 说明 |
|
|
113
|
+
|---|---|---|
|
|
114
|
+
| **观察** | `browser_embedded_status` | 运行状态、本会话标签页 URL/标题、当前 `layer`(`sidebar`/`float`/`window`/`headless`)、`layerChanged`、是否有待处理的人工请求 |
|
|
115
|
+
| | `browser_embedded_page_info` | 轻量状态检查:URL、标题、`readyState`、视口、滚动位置、粗粒度验证码信号 |
|
|
116
|
+
| | `browser_embedded_snapshot` | 标题、URL、自适应编号的可交互元素清单(带稳定 `loc` 与 `offset` 翻页)、iframe 列表、可见正文 |
|
|
117
|
+
| | `browser_embedded_read_element` | 按 CSS 选择器读单个元素(`text`/`html`/`value`/`attribute`/`visible`/`enabled`/`count`) |
|
|
118
|
+
| | `browser_embedded_js` | 在页面中执行单条 JS 表达式(返回可 JSON 序列化结果,默认 await Promise) |
|
|
119
|
+
| | `browser_embedded_screenshot` | 截取视口、`fullPage` 或指定 `selector` 元素,以 PNG 图片附件返回(无附件服务时落盘至系统临时目录) |
|
|
120
|
+
| | `browser_embedded_wait` | 等待 `selector`、`url`、`function`、`load` 或 `delay`,替代盲目 sleep |
|
|
121
|
+
| **导航与框架** | `browser_embedded_navigate` | 打开 `http(s)` 网址(首次调用自动启动浏览器;`newTab` 用新标签页替换当前页) |
|
|
122
|
+
| | `browser_embedded_tab` | `list` 列出所有页面 target、`switch` 切换本会话绑定、`close` 关闭指定标签页 |
|
|
123
|
+
| | `browser_embedded_frame` | `op=open` 将跨域 iframe 的地址单独作为顶层页面打开以读取/操作(会丢失原页表单与滚动状态);`op=back` 重载原 URL |
|
|
124
|
+
| **操作** | `browser_embedded_click` | 支持快照 `index`、CSS `selector`、可见 `text`(先查语义控件,再兜底 `<span>`/`<div>` 等可点非语义元素;纯展示文字拒绝盲点并给出选择器)或视口坐标 `x`/`y`(用于跨域 iframe);支持 `double` 双击 |
|
|
125
|
+
| | `browser_embedded_type` | 点击聚焦并键入文本(兼容 React/Vue 受控输入;`submit: true` 附带回车);支持 `index`/`selector`/`x,y` |
|
|
126
|
+
| | `browser_embedded_fill` | 通过原生 setter 整体替换输入框值(兼容 React/Vue) |
|
|
127
|
+
| | `browser_embedded_press` | 派发单个按键(`Enter`、`Tab`、`Escape`、`Backspace`、`Delete`、方向键、`Home`/`End`、`PageUp`/`Down`、`Space`) |
|
|
128
|
+
| | `browser_embedded_hover` | 悬停到元素或 `x`/`y` 坐标(触发 CSS `:hover` 下拉菜单前必用) |
|
|
129
|
+
| | `browser_embedded_select` | 选择原生 `<select>` 下拉项(支持 value 或可见文本) |
|
|
130
|
+
| | `browser_embedded_check` | 幂等勾选或取消勾选复选框/单选框 |
|
|
131
|
+
| | `browser_embedded_scroll` | 滚动 `down`/`up`/`left`/`right`/`top`/`bottom`(可指定 `pixels`) |
|
|
132
|
+
| | `browser_embedded_drag` | 拖拽元素到目标(真实指针轨迹;面板内 `draggable` 元素走合成拖拽事件) |
|
|
133
|
+
| **文件与网络** | `browser_embedded_upload` | 向 `<input type="file">` 附加本地文件,不弹选择框(拦截敏感凭据与系统目录) |
|
|
134
|
+
| | `browser_embedded_download` | 设置下载目录或带页面 cookie 下载指定 URL,路径收敛在 `~/Downloads/dsh-embedded-browser` 内(越界拒绝) |
|
|
135
|
+
| | `browser_embedded_http` | 在页面上下文内 `fetch`,自动携带当前 profile 的 cookie(受同源/CORS 约束,`maxBytes` 截断) |
|
|
136
|
+
| | `browser_embedded_dialog` | 应答阻塞标签页的 `alert` / `confirm` / `prompt` 对话框 |
|
|
137
|
+
| **换层与人机交接** | `browser_embedded_present` | 在 `sidebar` / `float` / `window` 之间切换页面(受 `aiPresent*` 配置控制) |
|
|
138
|
+
| | `browser_embedded_ask_human` | 调出本会话的浏览器面板并显示操作提示横幅,等待人类点击 **我已完成** |
|
|
139
|
+
| | `browser_embedded_close` | 关闭本会话标签页并释放内存(保留共享 profile 与登录态) |
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## 右侧栏面板操作
|
|
144
|
+
|
|
145
|
+
- **按需弹出**:会话开始使用浏览器时自动打开 **浏览器 / Browser** tab,不用浏览器的会话界面保持清爽;也可在右侧栏引导页手动打开。
|
|
146
|
+
- **工具栏**:后退 / 前进 / 刷新 / 重绘、表单按键(`Tab` / `⇧Tab` / `Enter`)、**独立窗口**(切到插件托管的真实 Chromium 窗口,登录态持久保留)、**浮窗**(在 DSH 窗口内弹出浮动面板,浮动时变为 **收回**)、**设置**(实时调整驻留与闲置回收策略)以及 **结束并清理**。
|
|
147
|
+
- **人工接管横幅**:仅出现在发起请求的会话 tab 内,点 **我已完成** 即可让 AI 继续执行(可选附言);tab 标签上的小圆点用于提示某会话正在等人。
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## 浏览器探测与可选懒加载
|
|
152
|
+
|
|
153
|
+
- **自动探测顺序**:`browserPath` 配置 → `PATH` 上的 `google-chrome-stable` / `google-chrome` / `chromium` / `chromium-browser` / `chrome` → Playwright 缓存 → Puppeteer 缓存。
|
|
154
|
+
- **headed 模式**:**Windows / macOS** 上 `mode: headed` 直接打开真实浏览器窗口,无需 Xvfb;**Linux** 上 `Xvfb` 为可选项(缺失时自动回退 `--headless=new`)。
|
|
155
|
+
- **可选 `lazyTools: true`**:默认 `false` 下 26 个工具立即可用,不依赖任何技能。若设为 `true` 以节省非浏览器对话的 prompt token,则需调用 `browser-use` 技能(或发 `/browser-use`)解锁(技能名见 `lib/lazy.js` 的 `SKILL_NAME`)。
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## 快速验证
|
|
160
|
+
|
|
161
|
+
1. 让 AI 打开一个网页:
|
|
162
|
+
```text
|
|
163
|
+
用 browser_embedded_navigate 打开 https://example.com,然后调用 browser_embedded_snapshot。
|
|
164
|
+
```
|
|
165
|
+
(如开启了 `lazyTools: true`,先调用 `browser-use` 技能或输入 `/browser-use`。)
|
|
166
|
+
2. 右侧栏会自动弹出 **浏览器 / Browser** tab。
|
|
167
|
+
3. 测试人工接管:
|
|
168
|
+
```text
|
|
169
|
+
调用 browser_embedded_ask_human,说明写「请在面板里完成登录,然后点我已完成」。
|
|
170
|
+
```
|
|
171
|
+
点击 **我已完成** 后,工具立即返回,AI 带着已登录状态继续执行。
|
|
172
|
+
4. 新开一个会话访问同一站点:在宿主 Chrome(`headless` / `window`)下共享同一份持久 profile,无需重复登录。
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## 配置项
|
|
177
|
+
|
|
178
|
+
在 `cordis.patch.yml` 中按需覆盖(`config` 为整键替换,请写全需要自定义的字段):
|
|
179
|
+
|
|
180
|
+
```yaml
|
|
181
|
+
- id: embedded-browser
|
|
182
|
+
config:
|
|
183
|
+
mode: auto # auto | headed | headless
|
|
184
|
+
viewport: 1440x900
|
|
185
|
+
idleShutdownMinutes: 10
|
|
186
|
+
realBrowser: on-demand # on-demand | always | off
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
<details>
|
|
190
|
+
<summary>全部 33 个配置项一览</summary>
|
|
191
|
+
|
|
192
|
+
| 字段 | 默认值 | 说明 |
|
|
193
|
+
|---|---|---|
|
|
194
|
+
| `browserPath` | `''` | 显式指定 Chrome/Chromium 路径;空 = 自动探测。 |
|
|
195
|
+
| `profileDir` | `''` | 持久 profile 目录;空 = `$DSH_HOME/embedded-browser/profile`。 |
|
|
196
|
+
| `mode` | `'auto'` | `auto` = Linux 有 Xvfb 时走 headed,否则 headless;Windows/macOS 下 `headed` 打开真实浏览器窗口,`auto` 为 headless。 |
|
|
197
|
+
| `screen` | `'1440x900x24'` | Linux 私有 Xvfb 的虚拟屏分辨率(`WxHxD`)。 |
|
|
198
|
+
| `windowSize` | `'1440x900'` | `headed` 模式下的浏览器窗口尺寸。 |
|
|
199
|
+
| `viewport` | `'1440x900'` | 仿真页面视口与面板画布坐标空间。 |
|
|
200
|
+
| `xvfbDisplay` | `':99'` | 私有 Xvfb 首选 display 号(被占用自动顺延)。 |
|
|
201
|
+
| `port` | `0` | 固定 CDP DevTools 端口;`0` 自动选空闲端口。 |
|
|
202
|
+
| `startUrl` | `'about:blank'` | 新会话标签页的初始地址。 |
|
|
203
|
+
| `extraArgs` | `[]` | 额外的 Chromium 启动参数。 |
|
|
204
|
+
| `snapshotMaxChars` | `4000` | `browser_embedded_snapshot` 默认正文字符预算。 |
|
|
205
|
+
| `maxElements` | `0` | 每次快照列出的元素数;`0` = 自适应(80 下限、240 上限、字符预算,支持 `offset` 翻页)。填正整数则固定数量。 |
|
|
206
|
+
| `realBrowser` | `'on-demand'` | 原生面板浏览器策略:`on-demand`(空闲自动回收)、`always`(每会话常驻)、`off`(仅无头)。 |
|
|
207
|
+
| `reclaimIdleMinutes` | `15` | 未固定的原生面板浏览器空闲多久后自动回收(分钟)。 |
|
|
208
|
+
| `maxLiveBrowsers` | `3` | 同时存活的原生面板浏览器上限(`0` = 不限;超限时按 LRU 回收)。 |
|
|
209
|
+
| `idleShutdownMinutes` | `10` | 宿主 Chrome 空闲多久后关闭(`0` = 永不关闭)。无损回收:下次按原 URL 重开且保留 profile。可在面板「设置」里实时修改。 |
|
|
210
|
+
| `autoStart` | `false` | 随 DSH 启动时立即拉起宿主 Chrome,而非首次调用时启动。 |
|
|
211
|
+
| `lazyTools` | `false` | `false` = 加载即注册 26 个工具;`true` = 经 `browser-use` 技能触发后再注册。 |
|
|
212
|
+
| `aiPresent` | `'allow'` | 是否允许 AI 主动换层(`browser_embedded_present`):`allow` / `off`。 |
|
|
213
|
+
| `aiPresentFloat` | `true` | 是否允许 AI 将页面弹成浮窗。 |
|
|
214
|
+
| `aiPresentWindow` | `true` | 是否允许 AI 将页面送入独立浏览器窗口。 |
|
|
215
|
+
| `askHumanTimeoutSeconds` | `600` | `browser_embedded_ask_human` 默认等待超时(秒)。 |
|
|
216
|
+
| `startTimeoutMs` | `20000` | Chrome 启动后等待 DevTools 就绪的超时(毫秒)。 |
|
|
217
|
+
| `streamTransport` | `'mjpeg'` | 回退画面的传输方式:`mjpeg`(`<img>` 管线)或 `ws`(canvas 回退)。 |
|
|
218
|
+
| `screencastQuality` | `'balanced'` | 推流 JPEG 画质:`smooth`(70)、`balanced`(85)、`sharp`(95)。 |
|
|
219
|
+
| `screencastMaxWidth` | `0` | 推流画面最大宽度;`0` 按 `viewport × renderScale` 推导。 |
|
|
220
|
+
| `adaptiveStream` | `true` | 页面滚动/运动时临时降清晰度换流畅,静止后恢复锐利。 |
|
|
221
|
+
| `streamFastScale` | `0.55` | `adaptiveStream: true` 时运动帧的分辨率倍率。 |
|
|
222
|
+
| `streamFastQuality` | `50` | `adaptiveStream: true` 时运动帧的 JPEG 质量。 |
|
|
223
|
+
| `renderScale` | `1.5` | 视口光栅化倍率(`1` / `1.5` / `2`),保证高 DPI 屏文字锐利(不影响给模型的截图尺寸)。 |
|
|
224
|
+
| `fitPanelAspect` | `true` | 按右侧栏宽高比自适应视口高度,保持配置宽度不变。 |
|
|
225
|
+
| `maxViewportHeight` | `1000` | `fitPanelAspect: true` 时的视口高度上限(防止瀑布流页面停止加载)。 |
|
|
226
|
+
| `pollFrameMs` | `140` | 非前台会话轮询截帧的间隔(毫秒,最小 `60`)。 |
|
|
227
|
+
|
|
228
|
+
</details>
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## 安全须知
|
|
233
|
+
|
|
234
|
+
- **复用 Web UI 鉴权**:面板 HTTP 与 WebSocket 端点均受 DSH 会话认证保护,能访问 Web UI 的人即可操作宿主浏览器。
|
|
235
|
+
- **共享 profile 边界**:会话隔离页面状态、不隔离身份——所有使用宿主 Chrome 的会话共享 cookie 与登录态。请妥善保管 `$DSH_HOME/embedded-browser/profile`,切勿提交至 Git。
|
|
236
|
+
- **路径与命令围栏**:
|
|
237
|
+
- `browser_embedded_upload` 拒绝上传敏感凭据目录(`~/.ssh`、`~/.dsh`、`~/.gemini`、`~/.gnupg`、`~/.aws`、`~/.kube`、`~/.docker`)及操作系统核心目录。
|
|
238
|
+
- `browser_embedded_download` 强制将 `downloadPath` 收敛在 `~/Downloads/dsh-embedded-browser` 内,越界路径直接拒绝。
|
|
239
|
+
- Windows 外部链接打开改用 `rundll32.exe url.dll,FileProtocolHandler` 直传参数,杜绝 `cmd.exe` 命令注入。
|
|
240
|
+
- **非 root 运行**:尽量使用非 root 用户运行以保留 Chromium 沙箱;仅当宿主进程为 root 时插件才会自动追加 `--no-sandbox`。
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## 常见问题排查
|
|
245
|
+
|
|
246
|
+
- **找不到浏览器**:在 `cordis.patch.yml` 中配置 `browserPath`,显式指向本机 Chrome / Edge / Chromium 可执行文件。
|
|
247
|
+
- **profile 异常或想重置登录态**:关闭 DSH 后删除 `$DSH_HOME/embedded-browser/profile`,重启 DSH 即可在下次使用时自动重建干净目录。
|
|
248
|
+
- **查看运行日志**:诊断日志位于 `$DSH_HOME/logs/`(`browser-boot.log`、`browser-import.log`、`browser-stream.log`、`panel-trace.log`)。
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## 卸载与回退
|
|
253
|
+
|
|
254
|
+
```sh
|
|
255
|
+
dsh plugin --profile desktop remove dsh-embedded-browser-next
|
|
256
|
+
# 或在桌面端「插件」页直接点卸载,然后完整重启 DSH 桌面端
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
卸载不会删除 `$DSH_HOME/embedded-browser/profile`,重装后登录态仍在;如需彻底清除,手动删除该目录即可。
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## 开发与测试
|
|
264
|
+
|
|
265
|
+
```sh
|
|
266
|
+
npm test # 运行全部 37 个单元测试文件(320 项)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
插件日志写入 `$DSH_HOME/logs/`(`browser-boot.log`、`browser-import.log`、`browser-stream.log`、`panel-trace.log`);设置 `DSH_BROWSER_TRACE=off` 可关闭面板追踪日志。
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Bundle patch for dsh-embedded-browser-next: inserts the dual-face plugin row into the
|
|
2
|
+
# profile roster. The node half (exports ".") runs in the DSH host process
|
|
3
|
+
# (browser lifecycle, /api/dsh-embedded-browser routes, the browser_embedded_*
|
|
4
|
+
# tools) and the `dsh.client` declaration in package.json makes the browser half
|
|
5
|
+
# (exports "./client") load in the Web GUI as an on-demand right-Sidebar tab.
|
|
6
|
+
#
|
|
7
|
+
# Override any field of the plugin config from your own patch layer, e.g.
|
|
8
|
+
# - id: embedded-browser
|
|
9
|
+
# config:
|
|
10
|
+
# mode: headless
|
|
11
|
+
# idleShutdownMinutes: 15
|
|
12
|
+
# lazyTools: false # publish the tools at load instead of after
|
|
13
|
+
# # the browser-use skill is invoked
|
|
14
|
+
- insert:
|
|
15
|
+
- id: embedded-browser
|
|
16
|
+
name: 'dsh-embedded-browser-next'
|