dsh-browser-cdp 0.17.23 → 0.17.25
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/README.md +29 -0
- package/THIRD_PARTY_NOTICES.md +13 -0
- package/bin/cdp-cast-worker.mjs +93 -11
- package/dsh-plugin.json +1 -1
- package/lib/client.js +171 -15
- package/lib/index.js +300 -59
- package/lib/{launcher-DBaxfIsF.js → launcher-BadIUjAx.js} +160 -28
- package/lib/launcher-h0Ca5NV1.js +3 -0
- package/package.json +1 -1
- package/lib/launcher-CQyI8-By.js +0 -3
package/README.md
CHANGED
|
@@ -170,6 +170,35 @@ dshx list # 应显示:[on] dsh-
|
|
|
170
170
|
|
|
171
171
|
`bcdp_doctor` 会报告当前序列类型计数、CLI 实际解析到的路径与形态,以及(若同机装了上游 `dsh-ego-browser`)一条共存提示。
|
|
172
172
|
|
|
173
|
+
## Lightpanda 后端(可选引擎,beta)
|
|
174
|
+
|
|
175
|
+
[Lightpanda](https://lightpanda.io) 是面向 AI 的无头文本渲染浏览器(AGPL-3.0,本插件仅作 CDP 客户端使用)。它对插件来说就是一个**普通 CDP 端点**:设置面板添加并激活后,probe 会从 `/json/version` 的 `Browser: Lightpanda/…` **自动识别引擎**,badge 与 `bcdp_doctor` 显示 engine,能力降级自动生效(无需任何配置)。
|
|
176
|
+
|
|
177
|
+
### 分系统安装
|
|
178
|
+
|
|
179
|
+
| 系统 | 方式 |
|
|
180
|
+
|---|---|
|
|
181
|
+
| **Linux**(建议本机直装测试) | `curl -fsSL https://pkg.lightpanda.io/install.sh \| bash`(装入 `~/.local/bin`,确保 PATH 含它)→ `lightpanda serve --host 127.0.0.1 --port 9222` |
|
|
182
|
+
| **macOS**(建议本机直装测试) | 同上一键脚本(aarch64)→ 同 serve 命令 |
|
|
183
|
+
| **Windows**(内置方案 = WSL2,无原生版) | 管理员 PowerShell `wsl --install` → 重启 → `wsl --install -d Ubuntu` → WSL 内同 Linux 一键脚本 → WSL 内 `lightpanda serve …`;WSL2 自动把端口映射到 Windows localhost(**二进制只存在于 WSL 内,宿主侧没有文件,属预期**) |
|
|
184
|
+
| **Docker(备选)** | `docker run -d --name lightpanda -p 127.0.0.1:9222:9222 lightpanda/browser:nightly` |
|
|
185
|
+
|
|
186
|
+
装好后在本插件设置面板添加 CDP 端点 `http://127.0.0.1:9222` 并激活即可。可选:`export LIGHTPANDA_DISABLE_TELEMETRY=true` 关遥测。
|
|
187
|
+
|
|
188
|
+
### 能力降级矩阵(识别后自动生效)
|
|
189
|
+
|
|
190
|
+
| 能力 | Lightpanda 上的行为 |
|
|
191
|
+
|---|---|
|
|
192
|
+
| 导航 / JS / 点击 / 填表 / 键鼠 / 快照(AX 树)/ HTTP / 登录导入 / 等待族 | **无损可用** |
|
|
193
|
+
| `bcdp_screenshot` | PNG **文本级渲染**(无像素引擎,视觉保真低于 Chrome;runtime 本就发 png,零改动兼容) |
|
|
194
|
+
| jev 视觉链(`bcdp_jev_frame` 等) | 投影自动改发 PNG;输出带 `engine` / `rendering: text` 元数据 |
|
|
195
|
+
| 观察窗实时画面 | **关闭**——无 screencast 且无窗口,worker 不启动采集循环,面板显示降级提示 |
|
|
196
|
+
| 面板点选(inspect 路径) | **关闭**——无 Overlay 域 / bindingCalled 事件,返回 `engine-unsupported`(i18n);坐标回退路径保留 |
|
|
197
|
+
| `bcdp_download` | **关闭**——无 Page 下载事件,调用即返回结构化错误(不会挂起超时) |
|
|
198
|
+
| `bcdp_auth_flush` | 返回 `degraded: true`——引擎无 `Storage.flushCookies`,cookie 仅随引擎进程存活 |
|
|
199
|
+
|
|
200
|
+
识别失败的端点(`engine: unknown`)保持**全能力**——误判只应"少给",不应"错给"。
|
|
201
|
+
|
|
173
202
|
## 工具清单(38 个,前缀 `bcdp_`,完整索引见 `bcdp_help`)
|
|
174
203
|
|
|
175
204
|
| 类别 | 工具 |
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -37,6 +37,19 @@ Additional local modifications on top of upstream (see `runtime/ego-linux/src/ch
|
|
|
37
37
|
launched Chrome, so the agent browser can reach the network through a local proxy
|
|
38
38
|
without hijacking the CLI's own loopback CDP traffic.
|
|
39
39
|
|
|
40
|
+
## Lightpanda notice (optional backend)
|
|
41
|
+
|
|
42
|
+
[Lightpanda](https://lightpanda.io) (https://github.com/lightpanda-io/browser) is an
|
|
43
|
+
**optional** third-party browser engine the user may run themselves (native Linux/macOS
|
|
44
|
+
binary, WSL2, or Docker). This plugin uses it strictly over its CDP network protocol as
|
|
45
|
+
a CLIENT — no Lightpanda code is vendored, linked, aggregated, or distributed with this
|
|
46
|
+
plugin, and the user installs the binary independently. Under AGPL-3.0 this client-over-
|
|
47
|
+
network use does not create a combined work; this plugin remains MIT. Users and
|
|
48
|
+
distributors of Lightpanda itself must comply with its AGPL-3.0 license
|
|
49
|
+
(https://www.gnu.org/licenses/agpl-3.0.html). Telemetry of the Lightpanda binary is
|
|
50
|
+
opt-out via `LIGHTPANDA_DISABLE_TELEMETRY=true` (set automatically for plugin-managed
|
|
51
|
+
launches).
|
|
52
|
+
|
|
40
53
|
MIT License (as provided by the upstream project):
|
|
41
54
|
|
|
42
55
|
MIT License
|
package/bin/cdp-cast-worker.mjs
CHANGED
|
@@ -3827,6 +3827,7 @@ var CdpCaptureBackend = class {
|
|
|
3827
3827
|
getConfig;
|
|
3828
3828
|
onStatus;
|
|
3829
3829
|
onJpegFrame;
|
|
3830
|
+
imageFormat;
|
|
3830
3831
|
now;
|
|
3831
3832
|
setTimer;
|
|
3832
3833
|
clearTimer;
|
|
@@ -3838,12 +3839,13 @@ var CdpCaptureBackend = class {
|
|
|
3838
3839
|
metrics;
|
|
3839
3840
|
offFrame;
|
|
3840
3841
|
offDestroyed;
|
|
3841
|
-
constructor({ cdp, sessions, getConfig, onStatus, onJpegFrame, now = Date.now, setTimer = setTimeout, clearTimer = clearTimeout }) {
|
|
3842
|
+
constructor({ cdp, sessions, getConfig, onStatus, onJpegFrame, imageFormat = "jpeg", now = Date.now, setTimer = setTimeout, clearTimer = clearTimeout }) {
|
|
3842
3843
|
this.cdp = cdp;
|
|
3843
3844
|
this.sessions = sessions;
|
|
3844
3845
|
this.getConfig = getConfig;
|
|
3845
3846
|
this.onStatus = onStatus;
|
|
3846
3847
|
this.onJpegFrame = onJpegFrame;
|
|
3848
|
+
this.imageFormat = imageFormat;
|
|
3847
3849
|
this.now = now;
|
|
3848
3850
|
this.setTimer = setTimer;
|
|
3849
3851
|
this.clearTimer = clearTimer;
|
|
@@ -3887,8 +3889,8 @@ var CdpCaptureBackend = class {
|
|
|
3887
3889
|
});
|
|
3888
3890
|
try {
|
|
3889
3891
|
await this.cdp.call("Page.startScreencast", {
|
|
3890
|
-
format:
|
|
3891
|
-
quality: config.cdpQuality,
|
|
3892
|
+
format: this.imageFormat,
|
|
3893
|
+
...this.imageFormat === "jpeg" ? { quality: config.cdpQuality } : {},
|
|
3892
3894
|
maxWidth: config.cdpMaxWidth,
|
|
3893
3895
|
everyNthFrame: 1
|
|
3894
3896
|
}, session.sessionId);
|
|
@@ -4011,8 +4013,8 @@ var CdpCaptureBackend = class {
|
|
|
4011
4013
|
const session = await this.sessions.updateViewport(current.targetId);
|
|
4012
4014
|
const scale = session.viewportW > this.getConfig().cdpMaxWidth ? this.getConfig().cdpMaxWidth / session.viewportW : 1;
|
|
4013
4015
|
const result = await this.cdp.call("Page.captureScreenshot", {
|
|
4014
|
-
format:
|
|
4015
|
-
quality: this.getConfig().cdpQuality,
|
|
4016
|
+
format: this.imageFormat,
|
|
4017
|
+
...this.imageFormat === "jpeg" ? { quality: this.getConfig().cdpQuality } : {},
|
|
4016
4018
|
captureBeyondViewport: false,
|
|
4017
4019
|
...session.viewportW && session.viewportH ? { clip: {
|
|
4018
4020
|
x: 0,
|
|
@@ -4042,6 +4044,7 @@ var CaptureManager = class {
|
|
|
4042
4044
|
backendFactories;
|
|
4043
4045
|
getConfig;
|
|
4044
4046
|
onStatus;
|
|
4047
|
+
screencastSupported;
|
|
4045
4048
|
now;
|
|
4046
4049
|
setTimer;
|
|
4047
4050
|
clearTimer;
|
|
@@ -4056,10 +4059,11 @@ var CaptureManager = class {
|
|
|
4056
4059
|
transition;
|
|
4057
4060
|
stopTimer;
|
|
4058
4061
|
sweepTimer;
|
|
4059
|
-
constructor({ backendFactories, getConfig, onStatus, now = Date.now, setTimer = setTimeout, clearTimer = clearTimeout, leaseTtlMs = 12e4, idleGraceMs = 1500 }) {
|
|
4062
|
+
constructor({ backendFactories, getConfig, onStatus, screencastSupported = true, now = Date.now, setTimer = setTimeout, clearTimer = clearTimeout, leaseTtlMs = 12e4, idleGraceMs = 1500 }) {
|
|
4060
4063
|
this.backendFactories = backendFactories;
|
|
4061
4064
|
this.getConfig = getConfig;
|
|
4062
4065
|
this.onStatus = onStatus;
|
|
4066
|
+
this.screencastSupported = screencastSupported;
|
|
4063
4067
|
this.now = now;
|
|
4064
4068
|
this.setTimer = setTimer;
|
|
4065
4069
|
this.clearTimer = clearTimer;
|
|
@@ -4079,7 +4083,8 @@ var CaptureManager = class {
|
|
|
4079
4083
|
...fallbackReason ? {
|
|
4080
4084
|
code: "ffmpeg-fallback-cdp",
|
|
4081
4085
|
message: fallbackReason
|
|
4082
|
-
} : {}
|
|
4086
|
+
} : {},
|
|
4087
|
+
...screencastSupported ? {} : { engineUnsupported: true }
|
|
4083
4088
|
};
|
|
4084
4089
|
this.transition = Promise.resolve();
|
|
4085
4090
|
this.stopTimer = null;
|
|
@@ -4164,6 +4169,18 @@ var CaptureManager = class {
|
|
|
4164
4169
|
}
|
|
4165
4170
|
async #activate(backendName, targetId, force = false) {
|
|
4166
4171
|
if (!force && this.backend && this.backendName === backendName && this.targetId === targetId) return;
|
|
4172
|
+
if (!this.screencastSupported) {
|
|
4173
|
+
await this.#stopBackend("engine-unsupported");
|
|
4174
|
+
this.#setStatus({
|
|
4175
|
+
backend: backendName,
|
|
4176
|
+
state: "unsupported",
|
|
4177
|
+
targetId,
|
|
4178
|
+
code: "engine-unsupported",
|
|
4179
|
+
message: "the attached engine cannot capture frames (no screencast, no window)",
|
|
4180
|
+
engineUnsupported: true
|
|
4181
|
+
});
|
|
4182
|
+
return;
|
|
4183
|
+
}
|
|
4167
4184
|
await this.#stopBackend("backend-change");
|
|
4168
4185
|
const factory = this.backendFactories[backendName];
|
|
4169
4186
|
if (!factory) {
|
|
@@ -6252,9 +6269,64 @@ async function captureMarked(call, sessionId, options = {}) {
|
|
|
6252
6269
|
};
|
|
6253
6270
|
}
|
|
6254
6271
|
|
|
6272
|
+
//#endregion
|
|
6273
|
+
//#region src/cdp/capabilities.ts
|
|
6274
|
+
const FULL = {
|
|
6275
|
+
engine: "chrome",
|
|
6276
|
+
screencast: true,
|
|
6277
|
+
overlay: true,
|
|
6278
|
+
bindingCalled: true,
|
|
6279
|
+
imageFormat: "jpeg",
|
|
6280
|
+
loadEvent: true,
|
|
6281
|
+
downloadEvents: true,
|
|
6282
|
+
browserClose: true
|
|
6283
|
+
};
|
|
6284
|
+
/**
|
|
6285
|
+
* The capability projection per engine. `chrome` / `unknown` → full
|
|
6286
|
+
* capabilities (bit-for-bit today's behavior); `lightpanda` → the analysis
|
|
6287
|
+
* (docs/plans/2026-10-04-lightpanda-backend-analysis.md §7) projection.
|
|
6288
|
+
*/
|
|
6289
|
+
function capabilitiesFor(engine) {
|
|
6290
|
+
if (engine === "lightpanda") return {
|
|
6291
|
+
engine: "lightpanda",
|
|
6292
|
+
screencast: false,
|
|
6293
|
+
overlay: false,
|
|
6294
|
+
bindingCalled: false,
|
|
6295
|
+
imageFormat: "png",
|
|
6296
|
+
loadEvent: false,
|
|
6297
|
+
downloadEvents: false,
|
|
6298
|
+
browserClose: false
|
|
6299
|
+
};
|
|
6300
|
+
return {
|
|
6301
|
+
...FULL,
|
|
6302
|
+
engine
|
|
6303
|
+
};
|
|
6304
|
+
}
|
|
6305
|
+
/**
|
|
6306
|
+
* Env key the host half sets when spawning the cast / render workers
|
|
6307
|
+
* (mirrors `EGO_LINUX_CDP_URL`'s injection pattern in cast-server). The child
|
|
6308
|
+
* processes cannot see the host's attach cache, so the projected engine id
|
|
6309
|
+
* travels as data — the host decides once, children only read.
|
|
6310
|
+
*/
|
|
6311
|
+
const BCDP_CDP_ENGINE = "BCDP_CDP_ENGINE";
|
|
6312
|
+
/**
|
|
6313
|
+
* Project capabilities from the spawn-env value. Anything absent or
|
|
6314
|
+
* unrecognized means FULL capabilities — an unknown engine must never
|
|
6315
|
+
* conservatively break a Chrome endpoint.
|
|
6316
|
+
*/
|
|
6317
|
+
function capabilitiesFromEnvValue(value) {
|
|
6318
|
+
return capabilitiesFor(value !== void 0 && value.trim() === "lightpanda" ? "lightpanda" : "unknown");
|
|
6319
|
+
}
|
|
6320
|
+
|
|
6255
6321
|
//#endregion
|
|
6256
6322
|
//#region src/worker/cdp-cast-worker.ts
|
|
6257
6323
|
const SENTINEL = "@@DSH_RESULT@@";
|
|
6324
|
+
/**
|
|
6325
|
+
* Lightpanda backend — capability projection for THIS connection. The host
|
|
6326
|
+
* decides once (probe → attach cache → spawn env); the worker only reads.
|
|
6327
|
+
* Absent env = full capabilities = pre-Lightpanda behavior.
|
|
6328
|
+
*/
|
|
6329
|
+
const CAPS = capabilitiesFromEnvValue(process.env[BCDP_CDP_ENGINE]);
|
|
6258
6330
|
const HOME = homedir() || process.env.HOME || process.env.USERPROFILE || "/root";
|
|
6259
6331
|
const IS_WIN = platform() === "win32";
|
|
6260
6332
|
const STATE_HOME = IS_WIN ? process.env.LOCALAPPDATA || join(HOME, "AppData", "Local") : process.env.XDG_STATE_HOME || join(HOME, ".local", "state");
|
|
@@ -6437,7 +6509,10 @@ function publishJpeg(frame) {
|
|
|
6437
6509
|
viewportH: frame.vh
|
|
6438
6510
|
});
|
|
6439
6511
|
while (frameCache.size > 30) frameCache.delete(frameCache.keys().next().value);
|
|
6440
|
-
broadcast("frame", frame
|
|
6512
|
+
broadcast("frame", frame.data !== void 0 && CAPS.imageFormat === "png" ? {
|
|
6513
|
+
...frame,
|
|
6514
|
+
fmt: "png"
|
|
6515
|
+
} : frame);
|
|
6441
6516
|
}
|
|
6442
6517
|
function publishVideoInit(event) {
|
|
6443
6518
|
videoInit = {
|
|
@@ -6485,6 +6560,7 @@ function endVideo({ generation } = {}) {
|
|
|
6485
6560
|
const manager = new CaptureManager({
|
|
6486
6561
|
getConfig: () => castConfig,
|
|
6487
6562
|
onStatus: publishStatus,
|
|
6563
|
+
screencastSupported: CAPS.screencast,
|
|
6488
6564
|
backendFactories: {
|
|
6489
6565
|
cdp: ({ onStatus }) => {
|
|
6490
6566
|
if (!active) throw new Error("no live browser");
|
|
@@ -6493,7 +6569,8 @@ const manager = new CaptureManager({
|
|
|
6493
6569
|
sessions: active.sessions,
|
|
6494
6570
|
getConfig: () => castConfig,
|
|
6495
6571
|
onStatus,
|
|
6496
|
-
onJpegFrame: publishJpeg
|
|
6572
|
+
onJpegFrame: publishJpeg,
|
|
6573
|
+
imageFormat: CAPS.imageFormat
|
|
6497
6574
|
});
|
|
6498
6575
|
},
|
|
6499
6576
|
ffmpeg: ({ generation, onStatus }) => {
|
|
@@ -6772,6 +6849,11 @@ async function main() {
|
|
|
6772
6849
|
code: "browser-disconnected",
|
|
6773
6850
|
error: "no live browser"
|
|
6774
6851
|
});
|
|
6852
|
+
if (body.enabled === true && (!CAPS.overlay || !CAPS.bindingCalled)) return sendJson(res, 503, {
|
|
6853
|
+
ok: false,
|
|
6854
|
+
code: "engine-unsupported",
|
|
6855
|
+
error: "this engine does not support Overlay-based picking"
|
|
6856
|
+
});
|
|
6775
6857
|
const channel = ensurePickChannel();
|
|
6776
6858
|
if (channel === null) return sendJson(res, 409, {
|
|
6777
6859
|
ok: false,
|
|
@@ -6870,8 +6952,8 @@ async function main() {
|
|
|
6870
6952
|
limit: typeof body.limit === "number" ? body.limit : 20,
|
|
6871
6953
|
highlightIndex: typeof body.highlightIndex === "number" ? body.highlightIndex : void 0,
|
|
6872
6954
|
measureRects: body.measureRects !== false,
|
|
6873
|
-
format: body.format === "jpeg" ? "jpeg" : "png",
|
|
6874
|
-
quality: typeof body.quality === "number" ? body.quality : void 0,
|
|
6955
|
+
format: CAPS.imageFormat === "png" ? "png" : body.format === "jpeg" ? "jpeg" : "png",
|
|
6956
|
+
quality: CAPS.imageFormat === "png" ? void 0 : typeof body.quality === "number" ? body.quality : void 0,
|
|
6875
6957
|
timeoutMs: 15e3
|
|
6876
6958
|
});
|
|
6877
6959
|
return sendJson(res, result.ok ? 200 : 502, result);
|