dsh-browser-cdp 0.18.18 → 0.18.21

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
@@ -172,6 +172,35 @@ dshx list # 应显示:[on] dsh-
172
172
 
173
173
  `bcdp_doctor` 会报告当前序列类型计数、CLI 实际解析到的路径与形态,以及(若同机装了上游 `dsh-ego-browser`)一条共存提示。
174
174
 
175
+ ## Lightpanda 后端(可选引擎,beta)
176
+
177
+ [Lightpanda](https://lightpanda.io) 是面向 AI 的无头文本渲染浏览器(AGPL-3.0,本插件仅作 CDP 客户端使用)。它对插件来说就是一个**普通 CDP 端点**:设置面板添加并激活后,probe 会从 `/json/version` 的 `Browser: Lightpanda/…` **自动识别引擎**,badge 与 `bcdp_doctor` 显示 engine,能力降级自动生效(无需任何配置)。
178
+
179
+ ### 分系统安装
180
+
181
+ | 系统 | 方式 |
182
+ |---|---|
183
+ | **Linux**(建议本机直装测试) | `curl -fsSL https://pkg.lightpanda.io/install.sh \| bash`(装入 `~/.local/bin`,确保 PATH 含它)→ `lightpanda serve --host 127.0.0.1 --port 9222` |
184
+ | **macOS**(建议本机直装测试) | 同上一键脚本(aarch64)→ 同 serve 命令 |
185
+ | **Windows**(内置方案 = WSL2,无原生版) | 管理员 PowerShell `wsl --install` → 重启 → `wsl --install -d Ubuntu` → WSL 内同 Linux 一键脚本 → WSL 内 `lightpanda serve …`;WSL2 自动把端口映射到 Windows localhost(**二进制只存在于 WSL 内,宿主侧没有文件,属预期**) |
186
+ | **Docker(备选)** | `docker run -d --name lightpanda -p 127.0.0.1:9222:9222 lightpanda/browser:nightly` |
187
+
188
+ 装好后在本插件设置面板添加 CDP 端点 `http://127.0.0.1:9222` 并激活即可。可选:`export LIGHTPANDA_DISABLE_TELEMETRY=true` 关遥测。
189
+
190
+ ### 能力降级矩阵(识别后自动生效)
191
+
192
+ | 能力 | Lightpanda 上的行为 |
193
+ |---|---|
194
+ | 导航 / JS / 点击 / 填表 / 键鼠 / 快照(AX 树)/ HTTP / 登录导入 / 等待族 | **无损可用** |
195
+ | `bcdp_screenshot` | PNG **文本级渲染**(无像素引擎,视觉保真低于 Chrome;runtime 本就发 png,零改动兼容) |
196
+ | jev 视觉链(`bcdp_jev_frame` 等) | 投影自动改发 PNG;输出带 `engine` / `rendering: text` 元数据 |
197
+ | 观察窗实时画面 | **关闭**——无 screencast 且无窗口,worker 不启动采集循环,面板显示降级提示 |
198
+ | 面板点选(inspect 路径) | **关闭**——无 Overlay 域 / bindingCalled 事件,返回 `engine-unsupported`(i18n);坐标回退路径保留 |
199
+ | `bcdp_download` | **关闭**——无 Page 下载事件,调用即返回结构化错误(不会挂起超时) |
200
+ | `bcdp_auth_flush` | 返回 `degraded: true`——引擎无 `Storage.flushCookies`,cookie 仅随引擎进程存活 |
201
+
202
+ 识别失败的端点(`engine: unknown`)保持**全能力**——误判只应"少给",不应"错给"。
203
+
175
204
  ## 工具清单(38 个,前缀 `bcdp_`,完整索引见 `bcdp_help`)
176
205
 
177
206
  | 类别 | 工具 |
@@ -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
@@ -3832,6 +3832,7 @@ var CdpCaptureBackend = class {
3832
3832
  getConfig;
3833
3833
  onStatus;
3834
3834
  onJpegFrame;
3835
+ imageFormat;
3835
3836
  now;
3836
3837
  setTimer;
3837
3838
  clearTimer;
@@ -3843,12 +3844,13 @@ var CdpCaptureBackend = class {
3843
3844
  metrics;
3844
3845
  offFrame;
3845
3846
  offDestroyed;
3846
- constructor({ cdp, sessions, getConfig, onStatus, onJpegFrame, now = Date.now, setTimer = setTimeout, clearTimer = clearTimeout }) {
3847
+ constructor({ cdp, sessions, getConfig, onStatus, onJpegFrame, imageFormat = "jpeg", now = Date.now, setTimer = setTimeout, clearTimer = clearTimeout }) {
3847
3848
  this.cdp = cdp;
3848
3849
  this.sessions = sessions;
3849
3850
  this.getConfig = getConfig;
3850
3851
  this.onStatus = onStatus;
3851
3852
  this.onJpegFrame = onJpegFrame;
3853
+ this.imageFormat = imageFormat;
3852
3854
  this.now = now;
3853
3855
  this.setTimer = setTimer;
3854
3856
  this.clearTimer = clearTimer;
@@ -3892,8 +3894,8 @@ var CdpCaptureBackend = class {
3892
3894
  });
3893
3895
  try {
3894
3896
  await this.cdp.call("Page.startScreencast", {
3895
- format: "jpeg",
3896
- quality: config.cdpQuality,
3897
+ format: this.imageFormat,
3898
+ ...this.imageFormat === "jpeg" ? { quality: config.cdpQuality } : {},
3897
3899
  maxWidth: config.cdpMaxWidth,
3898
3900
  everyNthFrame: 1
3899
3901
  }, session.sessionId);
@@ -4016,8 +4018,8 @@ var CdpCaptureBackend = class {
4016
4018
  const session = await this.sessions.updateViewport(current.targetId);
4017
4019
  const scale = session.viewportW > this.getConfig().cdpMaxWidth ? this.getConfig().cdpMaxWidth / session.viewportW : 1;
4018
4020
  const result = await this.cdp.call("Page.captureScreenshot", {
4019
- format: "jpeg",
4020
- quality: this.getConfig().cdpQuality,
4021
+ format: this.imageFormat,
4022
+ ...this.imageFormat === "jpeg" ? { quality: this.getConfig().cdpQuality } : {},
4021
4023
  captureBeyondViewport: false,
4022
4024
  ...session.viewportW && session.viewportH ? { clip: {
4023
4025
  x: 0,
@@ -4047,6 +4049,7 @@ var CaptureManager = class {
4047
4049
  backendFactories;
4048
4050
  getConfig;
4049
4051
  onStatus;
4052
+ screencastSupported;
4050
4053
  now;
4051
4054
  setTimer;
4052
4055
  clearTimer;
@@ -4061,10 +4064,11 @@ var CaptureManager = class {
4061
4064
  transition;
4062
4065
  stopTimer;
4063
4066
  sweepTimer;
4064
- constructor({ backendFactories, getConfig, onStatus, now = Date.now, setTimer = setTimeout, clearTimer = clearTimeout, leaseTtlMs = 12e4, idleGraceMs = 1500 }) {
4067
+ constructor({ backendFactories, getConfig, onStatus, screencastSupported = true, now = Date.now, setTimer = setTimeout, clearTimer = clearTimeout, leaseTtlMs = 12e4, idleGraceMs = 1500 }) {
4065
4068
  this.backendFactories = backendFactories;
4066
4069
  this.getConfig = getConfig;
4067
4070
  this.onStatus = onStatus;
4071
+ this.screencastSupported = screencastSupported;
4068
4072
  this.now = now;
4069
4073
  this.setTimer = setTimer;
4070
4074
  this.clearTimer = clearTimer;
@@ -4084,7 +4088,8 @@ var CaptureManager = class {
4084
4088
  ...fallbackReason ? {
4085
4089
  code: "ffmpeg-fallback-cdp",
4086
4090
  message: fallbackReason
4087
- } : {}
4091
+ } : {},
4092
+ ...screencastSupported ? {} : { engineUnsupported: true }
4088
4093
  };
4089
4094
  this.transition = Promise.resolve();
4090
4095
  this.stopTimer = null;
@@ -4169,6 +4174,18 @@ var CaptureManager = class {
4169
4174
  }
4170
4175
  async #activate(backendName, targetId, force = false) {
4171
4176
  if (!force && this.backend && this.backendName === backendName && this.targetId === targetId) return;
4177
+ if (!this.screencastSupported) {
4178
+ await this.#stopBackend("engine-unsupported");
4179
+ this.#setStatus({
4180
+ backend: backendName,
4181
+ state: "unsupported",
4182
+ targetId,
4183
+ code: "engine-unsupported",
4184
+ message: "the attached engine cannot capture frames (no screencast, no window)",
4185
+ engineUnsupported: true
4186
+ });
4187
+ return;
4188
+ }
4172
4189
  await this.#stopBackend("backend-change");
4173
4190
  const factory = this.backendFactories[backendName];
4174
4191
  if (!factory) {
@@ -5475,6 +5492,45 @@ async function describeNode(call, sessionId, ref, timeoutMs) {
5475
5492
  };
5476
5493
  }
5477
5494
  }
5495
+ /**
5496
+ * Read an element's OWN visible text — the piece `DOM.describeNode` cannot see
5497
+ * at depth 0. Anchor/button text lives in the subtree, so a pure-text link
5498
+ * (<a>News</a>) carries no name attribute and describes as `name=""`; the
5499
+ * visible text IS the feature users (and slugs) recognize. Best-effort by
5500
+ * contract: any failure resolves to a LayerFailure, never throws — a text
5501
+ * read must not break a pick that already resolved.
5502
+ */
5503
+ async function readNodeText(call, sessionId, backendNodeId, timeoutMs) {
5504
+ try {
5505
+ const objectId = (await call("DOM.resolveNode", { backendNodeId }, {
5506
+ ...sessionId === void 0 ? {} : { sessionId },
5507
+ ...timeoutMs === void 0 ? {} : { timeoutMs }
5508
+ }))?.object?.objectId;
5509
+ if (typeof objectId !== "string") return {
5510
+ ok: false,
5511
+ code: "node-not-resolved",
5512
+ message: "DOM.resolveNode returned no objectId"
5513
+ };
5514
+ const result = await call("Runtime.callFunctionOn", {
5515
+ objectId,
5516
+ 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) || \"\"); }",
5517
+ returnByValue: true
5518
+ }, {
5519
+ ...sessionId === void 0 ? {} : { sessionId },
5520
+ ...timeoutMs === void 0 ? {} : { timeoutMs }
5521
+ });
5522
+ return {
5523
+ ok: true,
5524
+ text: typeof result?.result?.value === "string" ? result.result.value : ""
5525
+ };
5526
+ } catch (error) {
5527
+ return {
5528
+ ok: false,
5529
+ code: "text-read-failed",
5530
+ message: error instanceof Error ? error.message : String(error)
5531
+ };
5532
+ }
5533
+ }
5478
5534
  /** A CDP quad is 8 numbers: x1,y1 .. x4,y4. */
5479
5535
  function quadToRect(quad) {
5480
5536
  if (!Array.isArray(quad) || quad.length < 8) return null;
@@ -5959,6 +6015,11 @@ var PickChannel = class {
5959
6015
  this.#fail(semantics.code, semantics.message);
5960
6016
  return;
5961
6017
  }
6018
+ let displayName = semantics.name;
6019
+ if (displayName === "") {
6020
+ const text = await readNodeText(call, sessionId, backendNodeId);
6021
+ if (text.ok && text.text !== "") displayName = text.text;
6022
+ }
5962
6023
  const box = await boxModel(call, sessionId, { backendNodeId }, { scroll: scrollOffset });
5963
6024
  let pageUrl = "";
5964
6025
  let pageTitle = "";
@@ -5974,11 +6035,14 @@ var PickChannel = class {
5974
6035
  tag: semantics.tag,
5975
6036
  id: semantics.id,
5976
6037
  role: semantics.role,
5977
- name: semantics.name,
6038
+ name: displayName,
5978
6039
  keyboardFocusable: semantics.keyboardFocusable,
5979
6040
  rect: box.ok ? box.rect : null,
5980
6041
  documentRect: box.ok ? box.documentRect : null,
5981
- describe: describeElement(semantics),
6042
+ describe: describeElement({
6043
+ ...semantics,
6044
+ name: displayName
6045
+ }),
5982
6046
  source: {
5983
6047
  endpoint: this.#getEndpoint ? this.#getEndpoint() : "",
5984
6048
  targetId,
@@ -6210,9 +6274,64 @@ async function captureMarked(call, sessionId, options = {}) {
6210
6274
  };
6211
6275
  }
6212
6276
 
6277
+ //#endregion
6278
+ //#region src/cdp/capabilities.ts
6279
+ const FULL = {
6280
+ engine: "chrome",
6281
+ screencast: true,
6282
+ overlay: true,
6283
+ bindingCalled: true,
6284
+ imageFormat: "jpeg",
6285
+ loadEvent: true,
6286
+ downloadEvents: true,
6287
+ browserClose: true
6288
+ };
6289
+ /**
6290
+ * The capability projection per engine. `chrome` / `unknown` → full
6291
+ * capabilities (bit-for-bit today's behavior); `lightpanda` → the analysis
6292
+ * (docs/plans/2026-10-04-lightpanda-backend-analysis.md §7) projection.
6293
+ */
6294
+ function capabilitiesFor(engine) {
6295
+ if (engine === "lightpanda") return {
6296
+ engine: "lightpanda",
6297
+ screencast: false,
6298
+ overlay: false,
6299
+ bindingCalled: false,
6300
+ imageFormat: "png",
6301
+ loadEvent: false,
6302
+ downloadEvents: false,
6303
+ browserClose: false
6304
+ };
6305
+ return {
6306
+ ...FULL,
6307
+ engine
6308
+ };
6309
+ }
6310
+ /**
6311
+ * Env key the host half sets when spawning the cast / render workers
6312
+ * (mirrors `EGO_LINUX_CDP_URL`'s injection pattern in cast-server). The child
6313
+ * processes cannot see the host's attach cache, so the projected engine id
6314
+ * travels as data — the host decides once, children only read.
6315
+ */
6316
+ const BCDP_CDP_ENGINE = "BCDP_CDP_ENGINE";
6317
+ /**
6318
+ * Project capabilities from the spawn-env value. Anything absent or
6319
+ * unrecognized means FULL capabilities — an unknown engine must never
6320
+ * conservatively break a Chrome endpoint.
6321
+ */
6322
+ function capabilitiesFromEnvValue(value) {
6323
+ return capabilitiesFor(value !== void 0 && value.trim() === "lightpanda" ? "lightpanda" : "unknown");
6324
+ }
6325
+
6213
6326
  //#endregion
6214
6327
  //#region src/worker/cdp-cast-worker.ts
6215
6328
  const SENTINEL = "@@DSH_RESULT@@";
6329
+ /**
6330
+ * Lightpanda backend — capability projection for THIS connection. The host
6331
+ * decides once (probe → attach cache → spawn env); the worker only reads.
6332
+ * Absent env = full capabilities = pre-Lightpanda behavior.
6333
+ */
6334
+ const CAPS = capabilitiesFromEnvValue(process.env[BCDP_CDP_ENGINE]);
6216
6335
  const HOME = homedir() || process.env.HOME || process.env.USERPROFILE || "/root";
6217
6336
  const IS_WIN = platform() === "win32";
6218
6337
  const STATE_HOME = IS_WIN ? process.env.LOCALAPPDATA || join(HOME, "AppData", "Local") : process.env.XDG_STATE_HOME || join(HOME, ".local", "state");
@@ -6395,7 +6514,10 @@ function publishJpeg(frame) {
6395
6514
  viewportH: frame.vh
6396
6515
  });
6397
6516
  while (frameCache.size > 30) frameCache.delete(frameCache.keys().next().value);
6398
- broadcast("frame", frame);
6517
+ broadcast("frame", frame.data !== void 0 && CAPS.imageFormat === "png" ? {
6518
+ ...frame,
6519
+ fmt: "png"
6520
+ } : frame);
6399
6521
  }
6400
6522
  function publishVideoInit(event) {
6401
6523
  videoInit = {
@@ -6443,6 +6565,7 @@ function endVideo({ generation } = {}) {
6443
6565
  const manager = new CaptureManager({
6444
6566
  getConfig: () => castConfig,
6445
6567
  onStatus: publishStatus,
6568
+ screencastSupported: CAPS.screencast,
6446
6569
  backendFactories: {
6447
6570
  cdp: ({ onStatus }) => {
6448
6571
  if (!active) throw new Error("no live browser");
@@ -6451,7 +6574,8 @@ const manager = new CaptureManager({
6451
6574
  sessions: active.sessions,
6452
6575
  getConfig: () => castConfig,
6453
6576
  onStatus,
6454
- onJpegFrame: publishJpeg
6577
+ onJpegFrame: publishJpeg,
6578
+ imageFormat: CAPS.imageFormat
6455
6579
  });
6456
6580
  },
6457
6581
  ffmpeg: ({ generation, onStatus }) => {
@@ -6730,6 +6854,11 @@ async function main() {
6730
6854
  code: "browser-disconnected",
6731
6855
  error: "no live browser"
6732
6856
  });
6857
+ if (body.enabled === true && (!CAPS.overlay || !CAPS.bindingCalled)) return sendJson(res, 503, {
6858
+ ok: false,
6859
+ code: "engine-unsupported",
6860
+ error: "this engine does not support Overlay-based picking"
6861
+ });
6733
6862
  const channel = ensurePickChannel();
6734
6863
  if (channel === null) return sendJson(res, 409, {
6735
6864
  ok: false,
@@ -6828,8 +6957,8 @@ async function main() {
6828
6957
  limit: typeof body.limit === "number" ? body.limit : 20,
6829
6958
  highlightIndex: typeof body.highlightIndex === "number" ? body.highlightIndex : void 0,
6830
6959
  measureRects: body.measureRects !== false,
6831
- format: body.format === "jpeg" ? "jpeg" : "png",
6832
- quality: typeof body.quality === "number" ? body.quality : void 0,
6960
+ format: CAPS.imageFormat === "png" ? "png" : body.format === "jpeg" ? "jpeg" : "png",
6961
+ quality: CAPS.imageFormat === "png" ? void 0 : typeof body.quality === "number" ? body.quality : void 0,
6833
6962
  timeoutMs: 15e3
6834
6963
  });
6835
6964
  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.18.18",
5
+ "version": "0.18.21",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {