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/lib/client.js CHANGED
@@ -31,6 +31,8 @@ var module = { exports: {} }; var exports = module.exports;
31
31
  const MAX_LINKS = 32;
32
32
  /** Local ego CLI singleton default label — mirrors host `EGO_CLI_LABEL`. */
33
33
  const EGO_CLI_LABEL = "本机 ego CLI";
34
+ /** Lightpanda managed-serve singleton default label — mirrors host `LP_LABEL`. */
35
+ const LP_LABEL = "Lightpanda(受管)";
34
36
  /** Fresh id, same shape as the host `newTargetId()` (uuid, `t-` fallback). */
35
37
  function newLinkId() {
36
38
  const cryptoObj = globalThis.crypto;
@@ -86,12 +88,35 @@ function buildCliRow(input) {
86
88
  probeAt: 0
87
89
  };
88
90
  }
91
+ /** Full-field lightpanda row (`servePath` '' = host auto-resolve chain). */
92
+ function buildLpRow(input) {
93
+ const servePath = trimmed(input.servePath);
94
+ return {
95
+ kind: "lightpanda",
96
+ id: newLinkId(),
97
+ label: trimmed(input.label) || LP_LABEL,
98
+ servePath,
99
+ enabled: true,
100
+ note: "",
101
+ probeStatus: "unknown",
102
+ probeLatencyMs: 0,
103
+ probeError: "",
104
+ probeCode: "",
105
+ probeAt: 0
106
+ };
107
+ }
89
108
  /** Second ego-cli anywhere in the array would be silently dropped on read. */
90
109
  function hasCliLink(links) {
91
110
  return links.some(function(row) {
92
111
  return row.kind === "ego-cli";
93
112
  });
94
113
  }
114
+ /** Second lightpanda anywhere in the array would be silently dropped on read. */
115
+ function hasLpLink(links) {
116
+ return links.some(function(row) {
117
+ return row.kind === "lightpanda";
118
+ });
119
+ }
95
120
  function isFull(links) {
96
121
  return links.length >= MAX_LINKS;
97
122
  }
@@ -105,6 +130,10 @@ function addRow(links, row) {
105
130
  links,
106
131
  code: "ego-cli-already-exists"
107
132
  };
133
+ if (row.kind === "lightpanda" && hasLpLink(links)) return {
134
+ links,
135
+ code: "lightpanda-already-exists"
136
+ };
108
137
  if (links.length >= MAX_LINKS) return {
109
138
  links,
110
139
  code: "link-limit-reached"
@@ -162,7 +191,8 @@ function applyProbe(links, id, outcome, at) {
162
191
  probeLatencyMs: typeof outcome.latencyMs === "number" ? outcome.latencyMs : 0,
163
192
  probeError: outcome.ok ? "" : outcome.message || "",
164
193
  probeCode: outcome.ok ? "" : outcome.code || "",
165
- probeAt: at
194
+ probeAt: at,
195
+ ...outcome.engine === void 0 ? {} : { probeEngine: outcome.engine }
166
196
  });
167
197
  }
168
198
 
@@ -211,6 +241,8 @@ var watchEn = {
211
241
  pinned: "Pinned",
212
242
  realtime: "Live",
213
243
  noScreenshot: "(no screenshot — about:blank or browser not rendering)",
244
+ engineUnsupportedBanner: "(live view unsupported on this engine — Lightpanda renders text; use bcdp_snapshot / bcdp_screenshot instead)",
245
+ engineUnsupportedPick: "picking is unsupported on this engine (no Overlay / no live view) — use bcdp_snapshot to locate elements",
214
246
  noActivePages: "No active browser pages",
215
247
  noActiveHint: "Pages will appear here as the agent browses with bcdp_*",
216
248
  openExternal: "Open real page",
@@ -265,6 +297,11 @@ var watchEn = {
265
297
  linksActive: "active",
266
298
  linksAddCdp: "Add CDP endpoint",
267
299
  linksAddCli: "Add local ego CLI",
300
+ linksAddLp: "Add Lightpanda (managed)",
301
+ linksAddLpExists: "The Lightpanda link already exists — local-only, one per machine",
302
+ linksLpPathHint: "Empty = auto (PATH → ~/.local/bin; Windows runs it inside WSL2)",
303
+ linksLpHeadlessHint: "Headless quick-trial engine — no manual fallback (login/captcha). Early in the order = quick trials use it; after the headed kinds (CDP / local Chrome / ego CLI) = backstop first.",
304
+ linksLpRemoteWarn: "Activating a Lightpanda link under cdpMode=remote fails with mode-kind-mismatch",
268
305
  linksAddCliExists: "The local ego CLI link already exists — local-only, one per machine",
269
306
  linksEndpoint: "Endpoint",
270
307
  linksEndpointHint: "http(s)://host:port or ws(s)://…",
@@ -300,6 +337,8 @@ var watchDict = {
300
337
  pinned: "已固定查看",
301
338
  realtime: "正在实时浏览",
302
339
  noScreenshot: "(暂无截图 — about:blank 或浏览器未渲染)",
340
+ engineUnsupportedBanner: "(当前引擎不支持实时画面 — Lightpanda 为文本渲染,可用 bcdp_snapshot / bcdp_screenshot 查看)",
341
+ engineUnsupportedPick: "当前引擎不支持面板点选(无 Overlay/无实时画面)— 请用 bcdp_snapshot 定位元素",
303
342
  noActivePages: "暂无活跃浏览器页",
304
343
  noActiveHint: "当 agent 开始用 bcdp_* 操作网页时,这里会实时显示",
305
344
  openExternal: "⧉ 打开真实页",
@@ -354,6 +393,11 @@ var watchDict = {
354
393
  linksActive: "已激活",
355
394
  linksAddCdp: "添加 CDP 端点",
356
395
  linksAddCli: "添加本机 ego CLI",
396
+ linksAddLp: "添加 Lightpanda(受管)",
397
+ linksAddLpExists: "Lightpanda 连接已存在——仅限本机,一台机器只允许一条",
398
+ linksLpPathHint: "留空 = 自动检测(PATH → ~/.local/bin;Windows 经 WSL2)",
399
+ linksLpHeadlessHint: "无头快速试验引擎:无法人工兜底(登录/验证码)。排前面 = 快速场景优先用它;排在有头类型(CDP/本机 Chrome/ego CLI)后 = 兜底优先。",
400
+ linksLpRemoteWarn: "cdpMode=remote 时激活 Lightpanda 行会报 mode-kind-mismatch",
357
401
  linksAddCliExists: "本机 ego CLI 连接已存在——仅限本机,一台机器只允许一条",
358
402
  linksEndpoint: "端点",
359
403
  linksEndpointHint: "http(s)://主机:端口 或 ws(s)://…",
@@ -1504,6 +1548,8 @@ function FamLinks(props) {
1504
1548
  var addEndpoint = addEndpointState[0], setAddEndpoint = addEndpointState[1];
1505
1549
  var addCliPathState = React.useState("");
1506
1550
  var addCliPath = addCliPathState[0], setAddCliPath = addCliPathState[1];
1551
+ var addLpPathState = React.useState("");
1552
+ var addLpPath = addLpPathState[0], setAddLpPath = addLpPathState[1];
1507
1553
  var btnStyle = {
1508
1554
  font: "inherit",
1509
1555
  fontSize: "12px",
@@ -1578,6 +1624,20 @@ function FamLinks(props) {
1578
1624
  setAddCliPath("");
1579
1625
  setErrText("");
1580
1626
  }
1627
+ function addLp() {
1628
+ var res = addRow(links, buildLpRow({
1629
+ label: "",
1630
+ servePath: addLpPath
1631
+ }));
1632
+ if (res.code) {
1633
+ setErrText(res.code === "link-limit-reached" ? limitText() : wt("linksAddLpExists"));
1634
+ return;
1635
+ }
1636
+ writeLinks(res.links);
1637
+ if (activeId === "") scope.set("activeTargetId", res.links[res.links.length - 1].id);
1638
+ setAddLpPath("");
1639
+ setErrText("");
1640
+ }
1581
1641
  function removeOne(row) {
1582
1642
  var res = removeRow(links, row.id);
1583
1643
  writeLinks(res.links);
@@ -1593,6 +1653,7 @@ function FamLinks(props) {
1593
1653
  code: "probe-failed",
1594
1654
  message: "no outcome"
1595
1655
  };
1656
+ if (outcome && outcome.engine === void 0 && outcome.ok === true) outcome.engine = "chrome";
1596
1657
  writeLinks(applyProbe(links, row.id, outcome, Date.now()));
1597
1658
  }).catch(function(error) {
1598
1659
  writeLinks(applyProbe(links, row.id, {
@@ -1661,6 +1722,7 @@ function FamLinks(props) {
1661
1722
  padding: "2px 0"
1662
1723
  } }, wt("linksEmpty")) : links.map(function(row, idx) {
1663
1724
  var isCli = row.kind === "ego-cli";
1725
+ var isLp = row.kind === "lightpanda";
1664
1726
  var isActive = row.id !== void 0 && row.id === activeId;
1665
1727
  var probeBadge = null;
1666
1728
  if (row.probeStatus === "ok" || row.probeStatus === "error") probeBadge = h("span", {
@@ -1692,7 +1754,7 @@ function FamLinks(props) {
1692
1754
  onChange: function(e) {
1693
1755
  writeLinks(updateRow(links, row.id, { enabled: e.target.checked }));
1694
1756
  }
1695
- }), h("span", { style: badgeStyle }, isCli ? "CLI" : "CDP"), h(FamRowInput, {
1757
+ }), h("span", { style: badgeStyle }, isCli ? "CLI" : isLp ? "LP·无头" : "CDP"), h(FamRowInput, {
1696
1758
  v: row.label || "",
1697
1759
  writable,
1698
1760
  placeholder: wt("linksLabel"),
@@ -1718,14 +1780,18 @@ function FamLinks(props) {
1718
1780
  gap: "8px",
1719
1781
  flexWrap: "wrap"
1720
1782
  } }, h(FamRowInput, {
1721
- v: (isCli ? row.cliPath : row.endpoint) || "",
1783
+ v: (isCli ? row.cliPath : isLp ? row.servePath : row.endpoint) || "",
1722
1784
  writable,
1723
- placeholder: isCli ? wt("linksCliPathHint") : wt("linksEndpointHint"),
1785
+ placeholder: isCli ? wt("linksCliPathHint") : isLp ? wt("linksLpPathHint") : wt("linksEndpointHint"),
1724
1786
  onCommit: function(v) {
1725
1787
  if (isCli) {
1726
1788
  writeLinks(updateRow(links, row.id, { cliPath: v }));
1727
1789
  return;
1728
1790
  }
1791
+ if (isLp) {
1792
+ writeLinks(updateRow(links, row.id, { servePath: v }));
1793
+ return;
1794
+ }
1729
1795
  if (!isValidEndpoint(v)) {
1730
1796
  setErrText(wt("linksEndpointInvalid"));
1731
1797
  return;
@@ -1747,7 +1813,7 @@ function FamLinks(props) {
1747
1813
  onChange: function(e) {
1748
1814
  writeLinks(updateRow(links, row.id, { useSdkPath: e.target.checked }));
1749
1815
  }
1750
- }), wt("linksCliSdk")) : null, !isCli ? h("button", {
1816
+ }), wt("linksCliSdk")) : null, !isCli && !isLp ? h("button", {
1751
1817
  type: "button",
1752
1818
  disabled: !writable || probingId === row.id,
1753
1819
  style: btnStyle,
@@ -1778,11 +1844,15 @@ function FamLinks(props) {
1778
1844
  onClick: function() {
1779
1845
  removeOne(row);
1780
1846
  }
1781
- }, "✕"), isCli && cdpMode === "remote" ? h("span", { style: {
1847
+ }, "✕"), (isCli || isLp) && cdpMode === "remote" ? h("span", { style: {
1782
1848
  fontSize: "11px",
1783
1849
  color: "#ff9f0a",
1784
1850
  flex: "1 1 100%"
1785
- } }, wt("linksCliRemoteWarn")) : null));
1851
+ } }, wt(isCli ? "linksCliRemoteWarn" : "linksLpRemoteWarn")) : null, isLp ? h("span", { style: {
1852
+ fontSize: "11px",
1853
+ color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.7))",
1854
+ flex: "1 1 100%"
1855
+ } }, wt("linksLpHeadlessHint")) : null));
1786
1856
  }), localRow, h("div", { style: {
1787
1857
  display: "grid",
1788
1858
  gap: "6px",
@@ -1848,7 +1918,33 @@ function FamLinks(props) {
1848
1918
  title: hasCliLink(links) ? wt("linksAddCliExists") : isFull(links) ? limitText() : void 0,
1849
1919
  style: btnStyle,
1850
1920
  onClick: addCli
1851
- }, wt("linksAddCli"))), errText ? h("div", { style: {
1921
+ }, wt("linksAddCli"))), h("div", { style: {
1922
+ display: "flex",
1923
+ gap: "8px",
1924
+ alignItems: "center",
1925
+ flexWrap: "wrap"
1926
+ } }, h("input", {
1927
+ type: "text",
1928
+ value: addLpPath,
1929
+ disabled: !writable || isFull(links) || hasLpLink(links),
1930
+ placeholder: wt("linksLpPathHint"),
1931
+ style: Object.assign({
1932
+ flex: "1 1 160px",
1933
+ minWidth: 0
1934
+ }, inputStyle),
1935
+ onChange: function(e) {
1936
+ setAddLpPath(e.target.value);
1937
+ },
1938
+ onKeyDown: function(e) {
1939
+ if (e.key === "Enter") addLp();
1940
+ }
1941
+ }), h("button", {
1942
+ type: "button",
1943
+ disabled: !writable || isFull(links) || hasLpLink(links),
1944
+ title: hasLpLink(links) ? wt("linksAddLpExists") : isFull(links) ? limitText() : void 0,
1945
+ style: btnStyle,
1946
+ onClick: addLp
1947
+ }, wt("linksAddLp"))), errText ? h("div", { style: {
1852
1948
  fontSize: "11px",
1853
1949
  color: "#ff453a"
1854
1950
  } }, errText) : null));
@@ -2036,6 +2132,7 @@ function mountFloatingWatch(ctx) {
2036
2132
  const pageMeta = /* @__PURE__ */ new Map();
2037
2133
  const watchClientId = "floating-" + Math.random().toString(36).slice(2);
2038
2134
  let watchStarted = false, watchTargetId = null, watchRenewTimer = null, watchStopTimer = null, watchRequest = null, captureBackend = "cdp", streamGeneration = 0, streamState = "idle", streamMime = "video/mp4; codecs=\"avc1.42E01E\"", videoCleanup = null;
2135
+ let streamEngineUnsupported = false;
2039
2136
  const effectiveVisible = () => !panel.hidden;
2040
2137
  const stopVideo = () => {
2041
2138
  if (videoCleanup) try {
@@ -2051,12 +2148,14 @@ function mountFloatingWatch(ctx) {
2051
2148
  const nextGeneration = status.generation ?? streamGeneration;
2052
2149
  const nextState = status.state || streamState;
2053
2150
  const nextMime = status.mime || streamMime;
2054
- const changed = captureBackend !== nextBackend || streamGeneration !== nextGeneration || streamState !== nextState || streamMime !== nextMime;
2151
+ const nextUnsupported = status.engineUnsupported === true;
2152
+ const changed = captureBackend !== nextBackend || streamGeneration !== nextGeneration || streamState !== nextState || streamMime !== nextMime || streamEngineUnsupported !== nextUnsupported;
2055
2153
  captureBackend = nextBackend;
2056
2154
  streamGeneration = nextGeneration;
2057
2155
  streamState = nextState;
2058
2156
  status.message || status.code;
2059
2157
  streamMime = nextMime;
2158
+ streamEngineUnsupported = nextUnsupported;
2060
2159
  if (changed) {
2061
2160
  stopVideo();
2062
2161
  const current = lastList.find((s) => s.targetId === (selectedTabId || currentActiveId));
@@ -2449,7 +2548,7 @@ function mountFloatingWatch(ctx) {
2449
2548
  } else {
2450
2549
  const n = document.createElement("div");
2451
2550
  n.className = "dsh-ego-liveurl";
2452
- n.textContent = wt("noScreenshot");
2551
+ n.textContent = streamEngineUnsupported ? wt("engineUnsupportedBanner") : wt("noScreenshot");
2453
2552
  view.appendChild(n);
2454
2553
  }
2455
2554
  view.appendChild(t);
@@ -2576,7 +2675,7 @@ function mountFloatingWatch(ctx) {
2576
2675
  } else {
2577
2676
  const n = document.createElement("div");
2578
2677
  n.className = "dsh-ego-liveurl";
2579
- n.textContent = wt("noScreenshot");
2678
+ n.textContent = streamEngineUnsupported ? wt("engineUnsupportedBanner") : wt("noScreenshot");
2580
2679
  view.appendChild(n);
2581
2680
  }
2582
2681
  view.appendChild(t);
@@ -2683,7 +2782,7 @@ function mountFloatingWatch(ctx) {
2683
2782
  vh: m.vh
2684
2783
  });
2685
2784
  }
2686
- applyFrame(m.targetId, `data:image/jpeg;base64,${m.data}`, m.vw, m.vh);
2785
+ applyFrame(m.targetId, `data:image/${m.fmt === "png" ? "png" : "jpeg"};base64,${m.data}`, m.vw, m.vh);
2687
2786
  } catch {}
2688
2787
  });
2689
2788
  sse.addEventListener("spaces", (ev) => {
@@ -3380,7 +3479,7 @@ function latchPickInputActions(sessionId, actions) {
3380
3479
  };
3381
3480
  }
3382
3481
  function pickSlugOf(entry) {
3383
- var raw = String(entry && entry.describe || entry && entry.name || entry && entry.tag || "");
3482
+ var raw = String(entry && entry.name || entry && entry.describe || entry && entry.tag || "");
3384
3483
  raw = raw.replace(/["'`]/g, "").trim();
3385
3484
  return raw.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+/, "").slice(0, 12).replace(/-+$/, "");
3386
3485
  }
@@ -3627,6 +3726,10 @@ function createPickControl(onState, deliver) {
3627
3726
  post(true, targetId).then(function(res) {
3628
3727
  var state = res && res.ok !== false ? res.state : null;
3629
3728
  if (!state || state.enabled !== true) {
3729
+ if (res && res.code === "engine-unsupported") {
3730
+ emit("failed", wt("engineUnsupportedPick"));
3731
+ return;
3732
+ }
3630
3733
  emit("failed", state && state.message || res && res.error || wt("pickFailed"));
3631
3734
  return;
3632
3735
  }
@@ -3703,6 +3806,7 @@ function LivePreviewController(ctx) {
3703
3806
  this.streamGeneration = 0;
3704
3807
  this.streamState = "idle";
3705
3808
  this.streamMessage = "";
3809
+ this.engineUnsupported = false;
3706
3810
  this.streamMime = "video/mp4; codecs=\"avc1.42E01E\"";
3707
3811
  this.liveVideo = null;
3708
3812
  this.videoCleanup = null;
@@ -3760,6 +3864,7 @@ LivePreviewController.prototype._initialState = function() {
3760
3864
  streamMessage: "",
3761
3865
  streamGeneration: 0,
3762
3866
  streamMime: "video/mp4; codecs=\"avc1.42E01E\"",
3867
+ engineUnsupported: false,
3763
3868
  pick: "off",
3764
3869
  pickMessage: ""
3765
3870
  };
@@ -3840,6 +3945,7 @@ LivePreviewController.prototype._recompute = function() {
3840
3945
  s.streamMessage = self.streamMessage;
3841
3946
  s.streamGeneration = self.streamGeneration;
3842
3947
  s.streamMime = self.streamMime;
3948
+ s.engineUnsupported = self.engineUnsupported;
3843
3949
  s.pick = self._pick;
3844
3950
  s.pickMessage = self._pickMessage;
3845
3951
  });
@@ -3924,6 +4030,7 @@ LivePreviewController.prototype._applyCaptureStatus = function(status) {
3924
4030
  this.streamMessage = status.message || status.code || "";
3925
4031
  this.streamGeneration = nextGeneration;
3926
4032
  this.streamMime = status.mime || this.streamMime;
4033
+ this.engineUnsupported = status.engineUnsupported === true;
3927
4034
  if (generationChanged || this.backend !== "ffmpeg") this._destroyVideo();
3928
4035
  this._recompute();
3929
4036
  };
@@ -4105,7 +4212,7 @@ LivePreviewController.prototype.openStream = function() {
4105
4212
  vh: m.vh
4106
4213
  }));
4107
4214
  }
4108
- self.applyFrame(m.targetId, "data:image/jpeg;base64," + m.data, m.vw, m.vh);
4215
+ self.applyFrame(m.targetId, "data:image/" + (m.fmt === "png" ? "png" : "jpeg") + ";base64," + m.data, m.vw, m.vh);
4109
4216
  } catch (e) {}
4110
4217
  });
4111
4218
  this.sse.addEventListener("spaces", function(ev) {
@@ -4613,8 +4720,8 @@ function EgoBrowserTab(props) {
4613
4720
  onDoubleClick: function(e) {
4614
4721
  controller.handleDoubleClick(e);
4615
4722
  }
4616
- }) : h("div", { className: "dsh-ego-side-liveurl" }, state.streamMessage || wt("noScreenshot"));
4617
- body = h("div", { className: "dsh-ego-side-body" }, h("div", { className: "dsh-ego-side-liveview" }, h("div", { className: "dsh-ego-side-livebadge" }, h("span", { className: "dsh-ego-side-state-dot" + (state.pinned ? " pin" : state.busy ? " busy" : "") }), h("span", { style: { flex: 1 } }, (state.backend === "ffmpeg" ? "FFmpeg · H.264" : "CDP") + " · " + (state.streamState === "failed" ? state.streamMessage || wt("failed") : state.streamState) + (state.currentTargetId ? state.wiringStale ? " · " + wt("stale") : " · " + wt("captured") : "")), state.pinned ? h("button", {
4723
+ }) : h("div", { className: "dsh-ego-side-liveurl" }, state.engineUnsupported ? wt("engineUnsupportedBanner") : state.streamMessage || wt("noScreenshot"));
4724
+ body = h("div", { className: "dsh-ego-side-body" }, h("div", { className: "dsh-ego-side-liveview" }, h("div", { className: "dsh-ego-side-livebadge" }, h("span", { className: "dsh-ego-side-state-dot" + (state.pinned ? " pin" : state.busy ? " busy" : "") }), h("span", { style: { flex: 1 } }, (state.backend === "ffmpeg" ? "FFmpeg · H.264" : "CDP") + " · " + (state.streamState === "failed" ? state.streamMessage || wt("failed") : state.streamState === "unsupported" ? wt("engineUnsupportedBanner") : state.streamState) + (state.currentTargetId ? state.wiringStale ? " · " + wt("stale") : " · " + wt("captured") : "")), state.pinned ? h("button", {
4618
4725
  className: "dsh-ego-side-back",
4619
4726
  type: "button",
4620
4727
  onClick: function() {