dsh-browser-cdp 0.17.22 → 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 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
  | 类别 | 工具 |
@@ -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
@@ -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: "jpeg",
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: "jpeg",
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) {
@@ -5470,6 +5487,45 @@ async function describeNode(call, sessionId, ref, timeoutMs) {
5470
5487
  };
5471
5488
  }
5472
5489
  }
5490
+ /**
5491
+ * Read an element's OWN visible text — the piece `DOM.describeNode` cannot see
5492
+ * at depth 0. Anchor/button text lives in the subtree, so a pure-text link
5493
+ * (<a>News</a>) carries no name attribute and describes as `name=""`; the
5494
+ * visible text IS the feature users (and slugs) recognize. Best-effort by
5495
+ * contract: any failure resolves to a LayerFailure, never throws — a text
5496
+ * read must not break a pick that already resolved.
5497
+ */
5498
+ async function readNodeText(call, sessionId, backendNodeId, timeoutMs) {
5499
+ try {
5500
+ const objectId = (await call("DOM.resolveNode", { backendNodeId }, {
5501
+ ...sessionId === void 0 ? {} : { sessionId },
5502
+ ...timeoutMs === void 0 ? {} : { timeoutMs }
5503
+ }))?.object?.objectId;
5504
+ if (typeof objectId !== "string") return {
5505
+ ok: false,
5506
+ code: "node-not-resolved",
5507
+ message: "DOM.resolveNode returned no objectId"
5508
+ };
5509
+ const result = await call("Runtime.callFunctionOn", {
5510
+ objectId,
5511
+ functionDeclaration: "function () { const cap = (s) => String(s).replace(/\\s+/g, \" \").trim().slice(0, 60);\nif (this instanceof HTMLInputElement) return cap(this.value || this.placeholder || \"\");\nif (this instanceof HTMLImageElement) return cap(this.alt || \"\");\nif (this instanceof HTMLSelectElement) return cap(this.selectedOptions && this.selectedOptions[0] ? this.selectedOptions[0].text : \"\");\nreturn cap(this.getAttribute(\"aria-label\") || this.getAttribute(\"title\") || (this.innerText ?? this.textContent) || \"\"); }",
5512
+ returnByValue: true
5513
+ }, {
5514
+ ...sessionId === void 0 ? {} : { sessionId },
5515
+ ...timeoutMs === void 0 ? {} : { timeoutMs }
5516
+ });
5517
+ return {
5518
+ ok: true,
5519
+ text: typeof result?.result?.value === "string" ? result.result.value : ""
5520
+ };
5521
+ } catch (error) {
5522
+ return {
5523
+ ok: false,
5524
+ code: "text-read-failed",
5525
+ message: error instanceof Error ? error.message : String(error)
5526
+ };
5527
+ }
5528
+ }
5473
5529
  /** A CDP quad is 8 numbers: x1,y1 .. x4,y4. */
5474
5530
  function quadToRect(quad) {
5475
5531
  if (!Array.isArray(quad) || quad.length < 8) return null;
@@ -5954,6 +6010,11 @@ var PickChannel = class {
5954
6010
  this.#fail(semantics.code, semantics.message);
5955
6011
  return;
5956
6012
  }
6013
+ let displayName = semantics.name;
6014
+ if (displayName === "") {
6015
+ const text = await readNodeText(call, sessionId, backendNodeId);
6016
+ if (text.ok && text.text !== "") displayName = text.text;
6017
+ }
5957
6018
  const box = await boxModel(call, sessionId, { backendNodeId }, { scroll: scrollOffset });
5958
6019
  let pageUrl = "";
5959
6020
  let pageTitle = "";
@@ -5969,11 +6030,14 @@ var PickChannel = class {
5969
6030
  tag: semantics.tag,
5970
6031
  id: semantics.id,
5971
6032
  role: semantics.role,
5972
- name: semantics.name,
6033
+ name: displayName,
5973
6034
  keyboardFocusable: semantics.keyboardFocusable,
5974
6035
  rect: box.ok ? box.rect : null,
5975
6036
  documentRect: box.ok ? box.documentRect : null,
5976
- describe: describeElement(semantics),
6037
+ describe: describeElement({
6038
+ ...semantics,
6039
+ name: displayName
6040
+ }),
5977
6041
  source: {
5978
6042
  endpoint: this.#getEndpoint ? this.#getEndpoint() : "",
5979
6043
  targetId,
@@ -6205,9 +6269,64 @@ async function captureMarked(call, sessionId, options = {}) {
6205
6269
  };
6206
6270
  }
6207
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
+
6208
6321
  //#endregion
6209
6322
  //#region src/worker/cdp-cast-worker.ts
6210
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]);
6211
6330
  const HOME = homedir() || process.env.HOME || process.env.USERPROFILE || "/root";
6212
6331
  const IS_WIN = platform() === "win32";
6213
6332
  const STATE_HOME = IS_WIN ? process.env.LOCALAPPDATA || join(HOME, "AppData", "Local") : process.env.XDG_STATE_HOME || join(HOME, ".local", "state");
@@ -6390,7 +6509,10 @@ function publishJpeg(frame) {
6390
6509
  viewportH: frame.vh
6391
6510
  });
6392
6511
  while (frameCache.size > 30) frameCache.delete(frameCache.keys().next().value);
6393
- broadcast("frame", frame);
6512
+ broadcast("frame", frame.data !== void 0 && CAPS.imageFormat === "png" ? {
6513
+ ...frame,
6514
+ fmt: "png"
6515
+ } : frame);
6394
6516
  }
6395
6517
  function publishVideoInit(event) {
6396
6518
  videoInit = {
@@ -6438,6 +6560,7 @@ function endVideo({ generation } = {}) {
6438
6560
  const manager = new CaptureManager({
6439
6561
  getConfig: () => castConfig,
6440
6562
  onStatus: publishStatus,
6563
+ screencastSupported: CAPS.screencast,
6441
6564
  backendFactories: {
6442
6565
  cdp: ({ onStatus }) => {
6443
6566
  if (!active) throw new Error("no live browser");
@@ -6446,7 +6569,8 @@ const manager = new CaptureManager({
6446
6569
  sessions: active.sessions,
6447
6570
  getConfig: () => castConfig,
6448
6571
  onStatus,
6449
- onJpegFrame: publishJpeg
6572
+ onJpegFrame: publishJpeg,
6573
+ imageFormat: CAPS.imageFormat
6450
6574
  });
6451
6575
  },
6452
6576
  ffmpeg: ({ generation, onStatus }) => {
@@ -6725,6 +6849,11 @@ async function main() {
6725
6849
  code: "browser-disconnected",
6726
6850
  error: "no live browser"
6727
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
+ });
6728
6857
  const channel = ensurePickChannel();
6729
6858
  if (channel === null) return sendJson(res, 409, {
6730
6859
  ok: false,
@@ -6823,8 +6952,8 @@ async function main() {
6823
6952
  limit: typeof body.limit === "number" ? body.limit : 20,
6824
6953
  highlightIndex: typeof body.highlightIndex === "number" ? body.highlightIndex : void 0,
6825
6954
  measureRects: body.measureRects !== false,
6826
- format: body.format === "jpeg" ? "jpeg" : "png",
6827
- 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,
6828
6957
  timeoutMs: 15e3
6829
6958
  });
6830
6959
  return sendJson(res, result.ok ? 200 : 502, result);
package/dsh-plugin.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://dsh.community/schemas/dsh-plugin-0.15.json",
3
3
  "id": "dsh-browser-cdp",
4
4
  "name": "dsh-browser-cdp",
5
- "version": "0.17.22",
5
+ "version": "0.17.25",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {