dsh-browser-cdp 0.0.1 → 0.16.23
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 +27 -0
- package/README.md +285 -9
- package/THIRD_PARTY_NOTICES.md +62 -0
- package/bin/cdp-cast-worker.mjs +7012 -0
- package/bin/cdp-chrome-wrapper.sh +53 -0
- package/bin/cdp-render-worker.mjs +610 -0
- package/bin/record-normalize.d.mts +32 -0
- package/bin/record-normalize.mjs +156 -0
- package/cordis.patch.yml +17 -0
- package/dsh-plugin.json +148 -0
- package/lib/client.js +5985 -0
- package/lib/index.js +8923 -0
- package/lib/launcher-CQyI8-By.js +3 -0
- package/lib/launcher-DBaxfIsF.js +269 -0
- package/locale/de.json +6 -0
- package/locale/en.json +6 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/it.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/ko.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +94 -14
- package/runtime/PATCHES.md +30 -0
- package/runtime/ego-browser/dist/out/index.js +7206 -0
- package/runtime/ego-browser/screenshot-clip.d.mts +22 -0
- package/runtime/ego-browser/screenshot-clip.mjs +45 -0
- package/runtime/ego-linux/bin/ego-browser.mjs +399 -0
- package/runtime/ego-linux/src/agent-identity.mjs +65 -0
- package/runtime/ego-linux/src/chrome.mjs +867 -0
- package/runtime/ego-linux/src/cursor.mjs +1292 -0
- package/runtime/ego-linux/src/desktop.mjs +73 -0
- package/runtime/ego-linux/src/paths.mjs +35 -0
- package/runtime/ego-linux/src/session.mjs +37 -0
- package/runtime/ego-linux/src/shim.mjs +145 -0
- package/runtime/ego-linux/src/snapshot.mjs +424 -0
- package/runtime/ego-linux/src/spaces-server.mjs +355 -0
- package/runtime/ego-linux/src/spaces-ui.mjs +456 -0
- package/runtime/ego-linux/src/tabs.mjs +109 -0
- package/runtime/ego-linux/src/task-spaces.mjs +671 -0
- package/runtime/ego-linux/src/transport.mjs +321 -0
- package/runtime/ego-linux/src/window-fit.mjs +107 -0
- package/runtime/skills/ego-browser/SKILL.md +209 -0
- package/runtime/skills/ego-browser/agents/openai.yaml +7 -0
- package/runtime/skills/ego-browser/assets/composer-icon.png +0 -0
- package/runtime/skills/ego-browser/assets/logo.png +0 -0
- package/runtime/skills/ego-browser/learnings/google/browser-tools/autocomplete.js +11 -0
- package/runtime/skills/ego-browser/learnings/google/manifest.json +40 -0
- package/runtime/skills/ego-browser/learnings/google/notes/overview.md +23 -0
- package/runtime/skills/ego-browser/learnings/google/tools/search-extract.js +35 -0
- package/runtime/skills/ego-browser/learnings/x-com/browser-tools/extract-post.js +9 -0
- package/runtime/skills/ego-browser/learnings/x-com/manifest.json +51 -0
- package/runtime/skills/ego-browser/learnings/x-com/notes/overview.md +18 -0
- package/runtime/skills/ego-browser/learnings/x-com/notes/timeline.md +19 -0
- package/runtime/skills/ego-browser/learnings/x-com/tools/search-users.js +33 -0
- package/runtime/skills/ego-browser/learnings/x-com/tools/timeline.js +32 -0
- package/runtime/skills/ego-browser/references/install.md +131 -0
- package/runtime/skills/ego-browser/references/task-spaces.md +122 -0
- package/runtime/skills/ego-browser/references/video.md +17 -0
- package/runtime/skills/ego-browser/scripts/install.sh +309 -0
- package/index.js +0 -11
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type declarations for `record-normalize.mjs`.
|
|
3
|
+
*
|
|
4
|
+
* The normalizer is authored as plain ESM (`.mjs`) because the render worker
|
|
5
|
+
* imports it directly at runtime and is NOT compiled by tsdown. This companion
|
|
6
|
+
* declaration gives the TS test (and any TS consumer) types without pulling the
|
|
7
|
+
* worker into the build. Keep the shapes in sync with `record-normalize.mjs`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface ActedRecord {
|
|
11
|
+
/** Lowercased tag, e.g. "span". */
|
|
12
|
+
tagName: string
|
|
13
|
+
/** Page classes only — inspector-chrome tokens pruned. */
|
|
14
|
+
className: string
|
|
15
|
+
/** The element's own text, truncated to a byte budget. */
|
|
16
|
+
text: string
|
|
17
|
+
/** The full normalized outer HTML — the faithful record. Class preserved. */
|
|
18
|
+
outerHTML: string
|
|
19
|
+
backendNodeId: number
|
|
20
|
+
/** True when text/outerHTML were truncated to fit the budget. */
|
|
21
|
+
truncated: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Class tokens that are inspector chrome, not page content. Pruned, never kept. */
|
|
25
|
+
export const CHROME_CLASS_TOKENS: Set<string>
|
|
26
|
+
/** Attribute prefixes that are inspector chrome. Dropped entirely. */
|
|
27
|
+
export const CHROME_ATTR_PREFIXES: string[]
|
|
28
|
+
|
|
29
|
+
export function normalizeRecordedElement(
|
|
30
|
+
html: string,
|
|
31
|
+
backendNodeId: number,
|
|
32
|
+
): ActedRecord | null
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bin/record-normalize.mjs — turn a raw `DOM.getOuterHTML` string into the
|
|
3
|
+
* faithful, bounded "acted element" record.
|
|
4
|
+
*
|
|
5
|
+
* THE RULE (locked with the user, 2026-09-24):
|
|
6
|
+
*
|
|
7
|
+
* Rewriting rules ARE allowed — but LOCATING features such as `class` MUST be
|
|
8
|
+
* preserved.
|
|
9
|
+
*
|
|
10
|
+
* Concretely:
|
|
11
|
+
* - The `class` attribute is NEVER dropped. Only a small, explicit allowlist of
|
|
12
|
+
* known inspector-chrome class TOKENS (e.g. `trae-browser-inspect-draggable`)
|
|
13
|
+
* may be pruned from its value, and only when they are not page classes.
|
|
14
|
+
* - Other locating/semantic attributes (`id`, `role`, `name`, `href`, `type`,
|
|
15
|
+
* `value`, `placeholder`, `title`, `alt`, `aria-*`, `data-testid`, and any
|
|
16
|
+
* other `data-*`) are kept.
|
|
17
|
+
* - Transient / presentational attributes (`style`) are dropped — they are not
|
|
18
|
+
* locating features and they bloat the record.
|
|
19
|
+
* - Inner text is preserved verbatim, then truncated to a byte budget so a huge
|
|
20
|
+
* subtree cannot blow up the envelope. `truncated` tells the caller.
|
|
21
|
+
*
|
|
22
|
+
* This is the "package struct full record" the judge/loop keeps for the one
|
|
23
|
+
* element it acted on. It is deliberately NOT applied to every candidate in the
|
|
24
|
+
* frame: feeding full outerHTML for N candidates would defeat the count-bucketing
|
|
25
|
+
* the whole narrowing design relies on. One element, fully recorded — that is the
|
|
26
|
+
* right unit.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/** Class tokens that are inspector chrome, not page content. Pruned, never kept. */
|
|
30
|
+
export const CHROME_CLASS_TOKENS = new Set([
|
|
31
|
+
'trae-browser-inspect-draggable',
|
|
32
|
+
'trae-browser-inspect',
|
|
33
|
+
])
|
|
34
|
+
|
|
35
|
+
/** Attribute prefixes that are inspector chrome. Dropped entirely. */
|
|
36
|
+
export const CHROME_ATTR_PREFIXES = ['data-trae-']
|
|
37
|
+
|
|
38
|
+
/** Attributes kept as-is (locating / semantic). Anything not listed and not
|
|
39
|
+
* `data-*` / `aria-*` is dropped unless it is `class`. */
|
|
40
|
+
const KEEP_ATTR = new Set([
|
|
41
|
+
'id',
|
|
42
|
+
'role',
|
|
43
|
+
'name',
|
|
44
|
+
'href',
|
|
45
|
+
'type',
|
|
46
|
+
'value',
|
|
47
|
+
'placeholder',
|
|
48
|
+
'title',
|
|
49
|
+
'alt',
|
|
50
|
+
'tabindex',
|
|
51
|
+
'for',
|
|
52
|
+
])
|
|
53
|
+
|
|
54
|
+
const MAX_TEXT_BYTES = 600
|
|
55
|
+
const MAX_OUTER_BYTES = 2400
|
|
56
|
+
|
|
57
|
+
function isKeepAttr(name) {
|
|
58
|
+
if (KEEP_ATTR.has(name)) return true
|
|
59
|
+
if (name.startsWith('aria-')) return true
|
|
60
|
+
if (name === 'data-testid') return true
|
|
61
|
+
// Other data-* are kept: they often carry test/locating ids the page relies on.
|
|
62
|
+
if (name.startsWith('data-') && !CHROME_ATTR_PREFIXES.some((p) => name.startsWith(p))) return true
|
|
63
|
+
return false
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function normalizeClass(value) {
|
|
67
|
+
const tokens = String(value)
|
|
68
|
+
.split(/\s+/)
|
|
69
|
+
.map((t) => t.trim())
|
|
70
|
+
.filter((t) => t !== '' && !CHROME_CLASS_TOKENS.has(t))
|
|
71
|
+
return tokens.join(' ')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {string} html - raw outerHTML from `DOM.getOuterHTML`.
|
|
76
|
+
* @param {number} backendNodeId - the node this record is for.
|
|
77
|
+
* @returns {{ tagName: string, className: string, text: string, outerHTML: string, backendNodeId: number, truncated: boolean } | null}
|
|
78
|
+
*/
|
|
79
|
+
export function normalizeRecordedElement(html, backendNodeId) {
|
|
80
|
+
if (typeof html !== 'string' || html.trim() === '') return null
|
|
81
|
+
|
|
82
|
+
// Opening tag = up to the first `>` that is not inside a quoted attribute
|
|
83
|
+
// value. Records are small elements, so a tolerant scan is enough.
|
|
84
|
+
let end = -1
|
|
85
|
+
let inQuote = ''
|
|
86
|
+
for (let i = 1; i < html.length; i++) {
|
|
87
|
+
const ch = html[i]
|
|
88
|
+
if (inQuote) {
|
|
89
|
+
if (ch === inQuote) inQuote = ''
|
|
90
|
+
continue
|
|
91
|
+
}
|
|
92
|
+
if (ch === '"' || ch === "'") inQuote = ch
|
|
93
|
+
else if (ch === '>') {
|
|
94
|
+
end = i
|
|
95
|
+
break
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (end === -1) return null
|
|
99
|
+
|
|
100
|
+
const open = html.slice(0, end)
|
|
101
|
+
const rest = html.slice(end + 1) // includes children + closing tag
|
|
102
|
+
|
|
103
|
+
const tagMatch = open.match(/^<\s*([a-zA-Z][\w-]*)/)
|
|
104
|
+
if (!tagMatch) return null
|
|
105
|
+
const tagName = tagMatch[1].toLowerCase()
|
|
106
|
+
|
|
107
|
+
// Pull each attribute: name, optional ="value".
|
|
108
|
+
const attrs = []
|
|
109
|
+
const attrRe = /([a-zA-Z_][\w:-]*)(?:\s*=\s*"([^"]*)")?/g
|
|
110
|
+
let m
|
|
111
|
+
while ((m = attrRe.exec(open)) !== null) {
|
|
112
|
+
const name = m[1]
|
|
113
|
+
if (name.toLowerCase() === tagName) continue // the tag name itself
|
|
114
|
+
const value = m[2]
|
|
115
|
+
if (name === 'class') {
|
|
116
|
+
const classNorm = normalizeClass(value ?? '')
|
|
117
|
+
if (classNorm !== '') attrs.push(['class', classNorm])
|
|
118
|
+
continue
|
|
119
|
+
}
|
|
120
|
+
if (name === 'style') continue // transient / presentational
|
|
121
|
+
if (CHROME_ATTR_PREFIXES.some((p) => name.startsWith(p))) continue
|
|
122
|
+
if (!isKeepAttr(name)) continue
|
|
123
|
+
attrs.push([name, value ?? ''])
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Inner text (between opening and closing tag), for the compact citation.
|
|
127
|
+
const closeIdx = rest.lastIndexOf(`</${tagName}>`)
|
|
128
|
+
const inner = closeIdx >= 0 ? rest.slice(0, closeIdx) : rest
|
|
129
|
+
let text = inner.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim()
|
|
130
|
+
|
|
131
|
+
// Truncate text to a byte budget, then the whole outerHTML if still too big.
|
|
132
|
+
let truncated = false
|
|
133
|
+
if (text.length > MAX_TEXT_BYTES) {
|
|
134
|
+
text = text.slice(0, MAX_TEXT_BYTES) + '…'
|
|
135
|
+
truncated = true
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const attrStr = attrs.map(([k, v]) => (v === '' ? k : `${k}="${v}"`)).join(' ')
|
|
139
|
+
const rebuiltOpen = `<${tagName}${attrStr ? ' ' + attrStr : ''}>`
|
|
140
|
+
let outerHTML = rebuiltOpen + rest
|
|
141
|
+
|
|
142
|
+
if (outerHTML.length > MAX_OUTER_BYTES) {
|
|
143
|
+
// Cut from the middle of the children, keep the opening tag intact.
|
|
144
|
+
const keep = MAX_OUTER_BYTES - rebuiltOpen.length - 12
|
|
145
|
+
if (keep > 40) {
|
|
146
|
+
const head = rest.slice(0, Math.floor(keep / 2))
|
|
147
|
+
const tail = rest.slice(rest.length - Math.floor(keep / 2))
|
|
148
|
+
outerHTML = rebuiltOpen + head + '…(truncated)…' + tail
|
|
149
|
+
} else {
|
|
150
|
+
outerHTML = rebuiltOpen + '…(truncated)…'
|
|
151
|
+
}
|
|
152
|
+
truncated = true
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return { tagName, className: attrs.find((a) => a[0] === 'class')?.[1] ?? '', text, outerHTML, backendNodeId: Number(backendNodeId), truncated }
|
|
156
|
+
}
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Insert ego-browser: structured browser-automation tools (30+ bcdp_*) that drive
|
|
2
|
+
# the vendored ego-lite runtime through ctx.subprocess, plus a realtime watch
|
|
3
|
+
# panel (live SSE screencast + direct mouse interaction + download capture +
|
|
4
|
+
# human-verification notice + tab bar + login guide).
|
|
5
|
+
#
|
|
6
|
+
# All Config fields are optional — defaults are computed in lib/index.js
|
|
7
|
+
# (vendored runtime CLI, sane maxOutputBytes / graceMs, empty defaultSpace).
|
|
8
|
+
#
|
|
9
|
+
# [0.1.2 client contract] the loader row specifier MUST equal the package.json
|
|
10
|
+
# `name` (`dsh-browser-cdp`) — the client-modules scan matches the nearest
|
|
11
|
+
# manifest name against the Loader specifier, and the boot row id is the
|
|
12
|
+
# package name. The earlier `@dsh-external/ego-browser` alias (junction key)
|
|
13
|
+
# made the scan classify the entry as "not a client row": host tools kept
|
|
14
|
+
# working but the watch panel silently disappeared.
|
|
15
|
+
- insert:
|
|
16
|
+
- id: dsh-browser-cdp
|
|
17
|
+
name: "dsh-browser-cdp"
|
package/dsh-plugin.json
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://dsh.community/schemas/dsh-plugin-0.15.json",
|
|
3
|
+
"id": "dsh-browser-cdp",
|
|
4
|
+
"name": "dsh-browser-cdp",
|
|
5
|
+
"version": "0.16.23",
|
|
6
|
+
"manifestVersion": "0.15",
|
|
7
|
+
"facets": {
|
|
8
|
+
"host": {
|
|
9
|
+
"entry": "lib/index.js",
|
|
10
|
+
"apiVersion": "v1alpha1"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"requires": {
|
|
14
|
+
"contracts": [
|
|
15
|
+
{
|
|
16
|
+
"apiVersion": "presentation.dsh/v1alpha1",
|
|
17
|
+
"kind": "OpenExternal",
|
|
18
|
+
"optional": true,
|
|
19
|
+
"fallback": "report the URL as text instead of opening it"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"apiVersion": "presentation.dsh/v1alpha1",
|
|
23
|
+
"kind": "Notification",
|
|
24
|
+
"optional": true,
|
|
25
|
+
"fallback": "log the notice to the browser-status scene"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"permissions": [],
|
|
30
|
+
"contributes": {
|
|
31
|
+
"commands": [],
|
|
32
|
+
"x-dsh-tui": [
|
|
33
|
+
{
|
|
34
|
+
"apiVersion": "tui.dsh/v1alpha1",
|
|
35
|
+
"kind": "Scene",
|
|
36
|
+
"id": "dsh-browser-cdp.watch",
|
|
37
|
+
"name": "agent_browser",
|
|
38
|
+
"spec": {
|
|
39
|
+
"title": "Agent 浏览器",
|
|
40
|
+
"titles": {
|
|
41
|
+
"en": "Agent Browser",
|
|
42
|
+
"zh": "Agent 浏览器"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"apiVersion": "tui.dsh/v1alpha1",
|
|
48
|
+
"kind": "SettingsSection",
|
|
49
|
+
"id": "dsh-browser-cdp.settings",
|
|
50
|
+
"name": "dsh_browser_cdp_settings",
|
|
51
|
+
"spec": {
|
|
52
|
+
"namespace": "dsh-browser-cdp",
|
|
53
|
+
"title": "Agent 浏览器",
|
|
54
|
+
"titles": {
|
|
55
|
+
"en": "Agent Browser",
|
|
56
|
+
"zh": "Agent 浏览器"
|
|
57
|
+
},
|
|
58
|
+
"fields": [
|
|
59
|
+
{
|
|
60
|
+
"path": [
|
|
61
|
+
"isolateSpaces"
|
|
62
|
+
],
|
|
63
|
+
"label": "任务空间沙盒隔离 (Space isolation)",
|
|
64
|
+
"kind": "boolean",
|
|
65
|
+
"hint": "默认关闭:使用磁盘持久化 Profile,任务中登录的账号跨电脑重启永久保留;开启后使用内存临时沙盒隔离,任务结束不落盘。"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"path": [
|
|
69
|
+
"idleTimeoutMin"
|
|
70
|
+
],
|
|
71
|
+
"label": "空闲自动回收 (Idle auto-stop, minutes)",
|
|
72
|
+
"kind": "number",
|
|
73
|
+
"hint": "N 分钟没有任何 bcdp_* 调用后自动关闭后台浏览器进程(0 = 关闭此功能)。下次调用会自动冷启动(约 2-4 秒)。观察窗正在观看不算活动。"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"path": [
|
|
77
|
+
"chromePath"
|
|
78
|
+
],
|
|
79
|
+
"label": "Browser binary path",
|
|
80
|
+
"kind": "text",
|
|
81
|
+
"hint": "Path to the Chrome/Chromium/Edge binary. Empty = auto-detect."
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"path": [
|
|
85
|
+
"captureBackend"
|
|
86
|
+
],
|
|
87
|
+
"label": "Capture backend",
|
|
88
|
+
"kind": "select",
|
|
89
|
+
"options": [
|
|
90
|
+
{
|
|
91
|
+
"value": "auto",
|
|
92
|
+
"label": "Auto"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"value": "cdp",
|
|
96
|
+
"label": "CDP"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"value": "ffmpeg",
|
|
100
|
+
"label": "FFmpeg"
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"path": [
|
|
106
|
+
"streamProfile"
|
|
107
|
+
],
|
|
108
|
+
"label": "Quality profile",
|
|
109
|
+
"kind": "select",
|
|
110
|
+
"options": [
|
|
111
|
+
{
|
|
112
|
+
"value": "balanced",
|
|
113
|
+
"label": "Balanced"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"value": "quality",
|
|
117
|
+
"label": "Quality"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"value": "speed",
|
|
121
|
+
"label": "Speed"
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"path": [
|
|
127
|
+
"ffmpegPath"
|
|
128
|
+
],
|
|
129
|
+
"label": "FFmpeg binary path",
|
|
130
|
+
"kind": "text",
|
|
131
|
+
"hint": "Path to ffmpeg. Empty = auto-detect / on-demand install."
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
},
|
|
138
|
+
"subscriptions": [],
|
|
139
|
+
"license": "MIT",
|
|
140
|
+
"source": {
|
|
141
|
+
"repository": "https://github.com/drscrewdriver/dsh-browser-cdp"
|
|
142
|
+
},
|
|
143
|
+
"compat": {
|
|
144
|
+
"hosts": [
|
|
145
|
+
"dsh-tui"
|
|
146
|
+
]
|
|
147
|
+
}
|
|
148
|
+
}
|