dsh-browser-cdp 0.17.22 → 0.17.23

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.
@@ -5470,6 +5470,45 @@ async function describeNode(call, sessionId, ref, timeoutMs) {
5470
5470
  };
5471
5471
  }
5472
5472
  }
5473
+ /**
5474
+ * Read an element's OWN visible text — the piece `DOM.describeNode` cannot see
5475
+ * at depth 0. Anchor/button text lives in the subtree, so a pure-text link
5476
+ * (<a>News</a>) carries no name attribute and describes as `name=""`; the
5477
+ * visible text IS the feature users (and slugs) recognize. Best-effort by
5478
+ * contract: any failure resolves to a LayerFailure, never throws — a text
5479
+ * read must not break a pick that already resolved.
5480
+ */
5481
+ async function readNodeText(call, sessionId, backendNodeId, timeoutMs) {
5482
+ try {
5483
+ const objectId = (await call("DOM.resolveNode", { backendNodeId }, {
5484
+ ...sessionId === void 0 ? {} : { sessionId },
5485
+ ...timeoutMs === void 0 ? {} : { timeoutMs }
5486
+ }))?.object?.objectId;
5487
+ if (typeof objectId !== "string") return {
5488
+ ok: false,
5489
+ code: "node-not-resolved",
5490
+ message: "DOM.resolveNode returned no objectId"
5491
+ };
5492
+ const result = await call("Runtime.callFunctionOn", {
5493
+ objectId,
5494
+ 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) || \"\"); }",
5495
+ returnByValue: true
5496
+ }, {
5497
+ ...sessionId === void 0 ? {} : { sessionId },
5498
+ ...timeoutMs === void 0 ? {} : { timeoutMs }
5499
+ });
5500
+ return {
5501
+ ok: true,
5502
+ text: typeof result?.result?.value === "string" ? result.result.value : ""
5503
+ };
5504
+ } catch (error) {
5505
+ return {
5506
+ ok: false,
5507
+ code: "text-read-failed",
5508
+ message: error instanceof Error ? error.message : String(error)
5509
+ };
5510
+ }
5511
+ }
5473
5512
  /** A CDP quad is 8 numbers: x1,y1 .. x4,y4. */
5474
5513
  function quadToRect(quad) {
5475
5514
  if (!Array.isArray(quad) || quad.length < 8) return null;
@@ -5954,6 +5993,11 @@ var PickChannel = class {
5954
5993
  this.#fail(semantics.code, semantics.message);
5955
5994
  return;
5956
5995
  }
5996
+ let displayName = semantics.name;
5997
+ if (displayName === "") {
5998
+ const text = await readNodeText(call, sessionId, backendNodeId);
5999
+ if (text.ok && text.text !== "") displayName = text.text;
6000
+ }
5957
6001
  const box = await boxModel(call, sessionId, { backendNodeId }, { scroll: scrollOffset });
5958
6002
  let pageUrl = "";
5959
6003
  let pageTitle = "";
@@ -5969,11 +6013,14 @@ var PickChannel = class {
5969
6013
  tag: semantics.tag,
5970
6014
  id: semantics.id,
5971
6015
  role: semantics.role,
5972
- name: semantics.name,
6016
+ name: displayName,
5973
6017
  keyboardFocusable: semantics.keyboardFocusable,
5974
6018
  rect: box.ok ? box.rect : null,
5975
6019
  documentRect: box.ok ? box.documentRect : null,
5976
- describe: describeElement(semantics),
6020
+ describe: describeElement({
6021
+ ...semantics,
6022
+ name: displayName
6023
+ }),
5977
6024
  source: {
5978
6025
  endpoint: this.#getEndpoint ? this.#getEndpoint() : "",
5979
6026
  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.17.22",
5
+ "version": "0.17.23",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
package/lib/client.js CHANGED
@@ -4584,7 +4584,7 @@ function latchPickInputActions(sessionId, actions) {
4584
4584
  };
4585
4585
  }
4586
4586
  function pickSlugOf(entry) {
4587
- var raw = String(entry && entry.describe || entry && entry.name || entry && entry.tag || "");
4587
+ var raw = String(entry && entry.name || entry && entry.describe || entry && entry.tag || "");
4588
4588
  raw = raw.replace(/["'`]/g, "").trim();
4589
4589
  return raw.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+/, "").slice(0, 12).replace(/-+$/, "");
4590
4590
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-browser-cdp",
3
- "version": "0.17.22",
3
+ "version": "0.17.23",
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.1.7+ line: declarative settings via Config .volatile() fields; for DSH 0.1.2-rc.1 ~ 0.1.6 use the 0.16.x line]",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",