dsh-browser-cdp 0.18.18 → 0.18.19

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.
@@ -5475,6 +5475,45 @@ async function describeNode(call, sessionId, ref, timeoutMs) {
5475
5475
  };
5476
5476
  }
5477
5477
  }
5478
+ /**
5479
+ * Read an element's OWN visible text — the piece `DOM.describeNode` cannot see
5480
+ * at depth 0. Anchor/button text lives in the subtree, so a pure-text link
5481
+ * (<a>News</a>) carries no name attribute and describes as `name=""`; the
5482
+ * visible text IS the feature users (and slugs) recognize. Best-effort by
5483
+ * contract: any failure resolves to a LayerFailure, never throws — a text
5484
+ * read must not break a pick that already resolved.
5485
+ */
5486
+ async function readNodeText(call, sessionId, backendNodeId, timeoutMs) {
5487
+ try {
5488
+ const objectId = (await call("DOM.resolveNode", { backendNodeId }, {
5489
+ ...sessionId === void 0 ? {} : { sessionId },
5490
+ ...timeoutMs === void 0 ? {} : { timeoutMs }
5491
+ }))?.object?.objectId;
5492
+ if (typeof objectId !== "string") return {
5493
+ ok: false,
5494
+ code: "node-not-resolved",
5495
+ message: "DOM.resolveNode returned no objectId"
5496
+ };
5497
+ const result = await call("Runtime.callFunctionOn", {
5498
+ objectId,
5499
+ 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) || \"\"); }",
5500
+ returnByValue: true
5501
+ }, {
5502
+ ...sessionId === void 0 ? {} : { sessionId },
5503
+ ...timeoutMs === void 0 ? {} : { timeoutMs }
5504
+ });
5505
+ return {
5506
+ ok: true,
5507
+ text: typeof result?.result?.value === "string" ? result.result.value : ""
5508
+ };
5509
+ } catch (error) {
5510
+ return {
5511
+ ok: false,
5512
+ code: "text-read-failed",
5513
+ message: error instanceof Error ? error.message : String(error)
5514
+ };
5515
+ }
5516
+ }
5478
5517
  /** A CDP quad is 8 numbers: x1,y1 .. x4,y4. */
5479
5518
  function quadToRect(quad) {
5480
5519
  if (!Array.isArray(quad) || quad.length < 8) return null;
@@ -5959,6 +5998,11 @@ var PickChannel = class {
5959
5998
  this.#fail(semantics.code, semantics.message);
5960
5999
  return;
5961
6000
  }
6001
+ let displayName = semantics.name;
6002
+ if (displayName === "") {
6003
+ const text = await readNodeText(call, sessionId, backendNodeId);
6004
+ if (text.ok && text.text !== "") displayName = text.text;
6005
+ }
5962
6006
  const box = await boxModel(call, sessionId, { backendNodeId }, { scroll: scrollOffset });
5963
6007
  let pageUrl = "";
5964
6008
  let pageTitle = "";
@@ -5974,11 +6018,14 @@ var PickChannel = class {
5974
6018
  tag: semantics.tag,
5975
6019
  id: semantics.id,
5976
6020
  role: semantics.role,
5977
- name: semantics.name,
6021
+ name: displayName,
5978
6022
  keyboardFocusable: semantics.keyboardFocusable,
5979
6023
  rect: box.ok ? box.rect : null,
5980
6024
  documentRect: box.ok ? box.documentRect : null,
5981
- describe: describeElement(semantics),
6025
+ describe: describeElement({
6026
+ ...semantics,
6027
+ name: displayName
6028
+ }),
5982
6029
  source: {
5983
6030
  endpoint: this.#getEndpoint ? this.#getEndpoint() : "",
5984
6031
  targetId,
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.19",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
package/lib/client.js CHANGED
@@ -3380,7 +3380,7 @@ function latchPickInputActions(sessionId, actions) {
3380
3380
  };
3381
3381
  }
3382
3382
  function pickSlugOf(entry) {
3383
- var raw = String(entry && entry.describe || entry && entry.name || entry && entry.tag || "");
3383
+ var raw = String(entry && entry.name || entry && entry.describe || entry && entry.tag || "");
3384
3384
  raw = raw.replace(/["'`]/g, "").trim();
3385
3385
  return raw.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+/, "").slice(0, 12).replace(/-+$/, "");
3386
3386
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-browser-cdp",
3
- "version": "0.18.18",
3
+ "version": "0.18.19",
4
4
  "description": "dsh-browser-cdp: DSH browser plugin — attach to a running Chrome/Edge over CDP (no bundled browser needed); structured browser-automation tools (30+ bcdp_*) that drive the vendored ego runtime through ctx.subprocess, plus a realtime watch panel (live SSE screencast + direct mouse interaction + download capture + human-verification notice). Web shell: floating watch panel without dsh-better-sidebar, sidebar tab with it. Headless/TUI hosts: tools-only. [DSH 0.2.0-rc.1+ line: declarative settings via Config .volatile() fields; for DSH 0.1.2-rc.1 ~ 0.1.7 use the 0.17.x line]",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",