@restregular/dsh-visual-browser 0.0.0-stage → 0.1.1
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.md +129 -3
- package/client.js +835 -0
- package/cordis.patch.yml +17 -0
- package/icon.svg +21 -0
- package/index.js +43 -0
- package/lib/browser.js +1045 -0
- package/lib/cdp.js +208 -0
- package/lib/format.js +87 -0
- package/lib/page-scripts.js +528 -0
- package/lib/routes.js +201 -0
- package/lib/tools.js +168 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +70 -4
- package/test/format.test.mjs +62 -0
- package/test/package.test.mjs +56 -0
- package/test/routes.test.mjs +207 -0
- package/test/scripts.test.mjs +214 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 RestRegular
|
|
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.md
CHANGED
|
@@ -1,3 +1,129 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# dsh-visual-browser
|
|
2
|
+
|
|
3
|
+
A DeepSeek Harness plugin that gives the Agent a **real Chrome** and gives you a **window into it**.
|
|
4
|
+
|
|
5
|
+
- The Agent never reads the DOM. It reads a numbered list of *visible interactive
|
|
6
|
+
elements* plus a short text excerpt — a few hundred tokens per page instead of a
|
|
7
|
+
full snapshot.
|
|
8
|
+
- Every action the Agent takes (click, type, key, scroll, navigation) is mirrored
|
|
9
|
+
into a **面板 (panel)** with the page frame, an operation timeline you can replay,
|
|
10
|
+
and a picture you can click to take over the browser yourself.
|
|
11
|
+
- Cookies persist across restarts (one dedicated Chrome profile), so a login the
|
|
12
|
+
Agent performs once keeps working.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# The plugin is a normal DSH bundle; install it from the registry
|
|
18
|
+
dsh plugin add @restregular/dsh-visual-browser
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or from the Harness UI: **Plugins → Add → `@restregular/dsh-visual-browser`**.
|
|
22
|
+
|
|
23
|
+
Requirements: Google Chrome, Microsoft Edge, or Chromium on the machine
|
|
24
|
+
(auto-detected), and Node.js 22 or newer (the plugin ships no runtime
|
|
25
|
+
dependencies; it talks CDP over the built-in WebSocket).
|
|
26
|
+
|
|
27
|
+
## Use
|
|
28
|
+
|
|
29
|
+
1. Click the **浏览器 / Browser** icon in the sidebar to open the panel.
|
|
30
|
+
2. Ask the Agent something that needs a website, for example
|
|
31
|
+
*"打开 example.com 看看首页写了什么"*. The Agent calls `browser_open`.
|
|
32
|
+
3. Watch the frame update. Click the picture to click the page; wheel over it to
|
|
33
|
+
scroll; use the toolbar for back / forward / reload / live view / stop.
|
|
34
|
+
|
|
35
|
+
## Tools the Agent gets
|
|
36
|
+
|
|
37
|
+
| Tool | Purpose |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| `browser_open` | Open a URL (launches Chrome on first use) and return the numbered view. |
|
|
40
|
+
| `browser_see` | Fresh numbered view of the current page. |
|
|
41
|
+
| `browser_act` | `click` / `type` / `key` / `hover` / `scroll` / `select` / `back` / `forward` / `reload` / `wait` / `close`, then return the new view. |
|
|
42
|
+
| `browser_text` | Read text of the page or of one element (a link also returns its `href`). |
|
|
43
|
+
| `browser_screenshot` | Save a PNG/JPEG to disk and return the path (feed it to `read_image`). |
|
|
44
|
+
|
|
45
|
+
### What the Agent sees
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
URL: https://example.com/login
|
|
49
|
+
TITLE: 登录 - Example
|
|
50
|
+
VIEW: 1280x800 scroll 0/2400 · 4/6 interactive
|
|
51
|
+
[1] textbox "手机号" value=13800000000
|
|
52
|
+
[2] textbox "密码" value=••••••
|
|
53
|
+
[3] button "登录"
|
|
54
|
+
[4] link "忘记密码" → /forgot
|
|
55
|
+
HEADINGS: 用户登录 | 没有账号?
|
|
56
|
+
TEXT: 用户登录 手机号 密码 登录 忘记密码
|
|
57
|
+
ACTIVE: [1] textbox "手机号"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Numbers are reassigned on every view, so an action always uses the newest
|
|
61
|
+
numbers; a stale one fails with a clear "take a fresh snapshot" message instead
|
|
62
|
+
of clicking the wrong element.
|
|
63
|
+
|
|
64
|
+
## Configuration
|
|
65
|
+
|
|
66
|
+
Row config (in the profile's `cordis.patch.yml`, override by row id
|
|
67
|
+
`dsh-visual-browser`):
|
|
68
|
+
|
|
69
|
+
```yaml
|
|
70
|
+
- id: dsh-visual-browser
|
|
71
|
+
config:
|
|
72
|
+
headless: true # false = visible Chrome window
|
|
73
|
+
executablePath: '' # explicit chrome.exe path
|
|
74
|
+
userDataDir: '' # default: ~/.dsh/visual-browser/chrome-profile
|
|
75
|
+
viewport:
|
|
76
|
+
width: 1280
|
|
77
|
+
height: 800
|
|
78
|
+
maxElements: 100 # cap on the numbered list
|
|
79
|
+
maxTextChars: 320 # cap on the text excerpt
|
|
80
|
+
frameQuality: 62 # JPEG quality of panel frames
|
|
81
|
+
timelineFrames: 24 # replayable frames kept in memory
|
|
82
|
+
allowUserControl: true # allow clicks from the panel
|
|
83
|
+
reuseExisting: true # adopt a Chrome that already owns the profile
|
|
84
|
+
actionTimeoutMs: 12000
|
|
85
|
+
navigationTimeoutMs: 30000
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## How it works
|
|
89
|
+
|
|
90
|
+
- **Host** (`index.js`, `lib/`): launches Chrome with
|
|
91
|
+
`--remote-debugging-port=0 --user-data-dir=<profile>`, parses the DevTools
|
|
92
|
+
endpoint from stderr, attaches one flattened CDP session, and exposes:
|
|
93
|
+
- five tools through the `tools` service (registration is effect-scoped),
|
|
94
|
+
- a same-origin prefix route `/visual-browser/api` (`/state`, `/frame`,
|
|
95
|
+
`/live`, `/start`, `/stop`, `/capture`, `/click`, `/wheel`, `/key`, `/nav`)
|
|
96
|
+
that the panel polls and posts to.
|
|
97
|
+
- **Snapshot** (`lib/page-scripts.js`): one serialized function runs in the page,
|
|
98
|
+
filters interactive elements to the viewport, assigns `data-dsh-vb-ref`
|
|
99
|
+
numbers, and returns structured JSON. Nothing else about the DOM leaves the
|
|
100
|
+
page.
|
|
101
|
+
- **Frames** stay on the host: the panel displays the newest JPEG by sequence
|
|
102
|
+
number, so a live picture costs no session tokens. The timeline holds the last
|
|
103
|
+
N frames; clicking a row replays that moment.
|
|
104
|
+
- **One code path**: panel clicks, wheel events and keys run the same
|
|
105
|
+
`BrowserManager` methods the tools use.
|
|
106
|
+
- **Survives a host restart**: Chrome writes `DevToolsActivePort` into its
|
|
107
|
+
profile, so a restarted host (or one whose previous host crashed with Chrome
|
|
108
|
+
still alive) attaches to that browser instead of failing on the profile lock.
|
|
109
|
+
An adopted browser is only detached — its process is not killed.
|
|
110
|
+
|
|
111
|
+
Chrome is killed with its process tree when the plugin unloads.
|
|
112
|
+
|
|
113
|
+
## Notes and limits
|
|
114
|
+
|
|
115
|
+
- Cross-origin iframes are counted but not inspected; open the direct URL when a
|
|
116
|
+
flow lives inside a frame.
|
|
117
|
+
- Blocking JS dialogs are auto-accepted and logged in the timeline.
|
|
118
|
+
- The panel route is served by the Harness web server on its existing origin;
|
|
119
|
+
it performs no extra authentication, matching the other local panel routes.
|
|
120
|
+
- Headless mode is the default. Some sites behave differently headless; set
|
|
121
|
+
`headless: false` when a site insists on a window.
|
|
122
|
+
|
|
123
|
+
## Development
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
npm test # syntax checks + snapshot/format/route/package smoke tests
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
MIT © RestRegular
|