dsh-browser-cdp 0.18.17 → 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.
- package/bin/cdp-cast-worker.mjs +49 -2
- package/dsh-plugin.json +1 -1
- package/lib/client.js +15 -3
- package/package.json +1 -1
package/bin/cdp-cast-worker.mjs
CHANGED
|
@@ -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:
|
|
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(
|
|
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
package/lib/client.js
CHANGED
|
@@ -3379,6 +3379,16 @@ function latchPickInputActions(sessionId, actions) {
|
|
|
3379
3379
|
actions
|
|
3380
3380
|
};
|
|
3381
3381
|
}
|
|
3382
|
+
function pickSlugOf(entry) {
|
|
3383
|
+
var raw = String(entry && entry.name || entry && entry.describe || entry && entry.tag || "");
|
|
3384
|
+
raw = raw.replace(/["'`]/g, "").trim();
|
|
3385
|
+
return raw.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+/, "").slice(0, 12).replace(/-+$/, "");
|
|
3386
|
+
}
|
|
3387
|
+
function pickArchiveFileName(entry) {
|
|
3388
|
+
var slug = pickSlugOf(entry);
|
|
3389
|
+
var tail = Date.now().toString(36).slice(-5);
|
|
3390
|
+
return slug ? "picks-" + slug + "-" + tail + ".json" : "picks-" + tail + ".json";
|
|
3391
|
+
}
|
|
3382
3392
|
function needsBoundarySpace() {
|
|
3383
3393
|
var root = document.querySelector("[data-input-scroll] [contenteditable=\"true\"]");
|
|
3384
3394
|
var selection = window.getSelection();
|
|
@@ -3392,7 +3402,7 @@ function needsBoundarySpace() {
|
|
|
3392
3402
|
if (text === "") return false;
|
|
3393
3403
|
return !/\s/u.test(text.slice(-1));
|
|
3394
3404
|
}
|
|
3395
|
-
async function tryInsertPickChip(ctx, sessionId, actx, input, token) {
|
|
3405
|
+
async function tryInsertPickChip(ctx, sessionId, actx, input, token, label) {
|
|
3396
3406
|
try {
|
|
3397
3407
|
var latch = pickInputActionsLatch;
|
|
3398
3408
|
if (!latch.actions || latch.sessionId !== String(sessionId)) return false;
|
|
@@ -3404,7 +3414,7 @@ async function tryInsertPickChip(ctx, sessionId, actx, input, token) {
|
|
|
3404
3414
|
return input.insertReference({
|
|
3405
3415
|
source: "reference",
|
|
3406
3416
|
ref: token,
|
|
3407
|
-
label: "🌐 " + token.slice(1, -1),
|
|
3417
|
+
label: label || "🌐 " + token.slice(1, -1),
|
|
3408
3418
|
appearance: "file",
|
|
3409
3419
|
clipboardText: token
|
|
3410
3420
|
}, span) === true;
|
|
@@ -3507,13 +3517,15 @@ function deliverPickToConversation(ctx, element, action) {
|
|
|
3507
3517
|
pageTitle: src.pageTitle,
|
|
3508
3518
|
elements: [Object.assign({ n: 1 }, entry)]
|
|
3509
3519
|
};
|
|
3520
|
+
var newFile = pickArchiveFileName(entry);
|
|
3510
3521
|
var sres = await postJson("/bcdp/api/picks-save", {
|
|
3511
3522
|
block: JSON.stringify(pageNew, null, 2),
|
|
3523
|
+
file: newFile,
|
|
3512
3524
|
session: sessionId
|
|
3513
3525
|
});
|
|
3514
3526
|
if (!sres || sres.ok === false || !sres.value) return;
|
|
3515
3527
|
var token = "@\"picks/" + sres.value.file + "\"";
|
|
3516
|
-
if (!await tryInsertPickChip(ctx, sessionId, actx, input, token)) {
|
|
3528
|
+
if (!await tryInsertPickChip(ctx, sessionId, actx, input, token, "🌐 " + (pickSlugOf(entry) || sres.value.file.replace(/\.json$/, "")))) {
|
|
3517
3529
|
var cur = readDraftText(input);
|
|
3518
3530
|
cur = cur ? cur + (cur.charAt(cur.length - 1) === "\n" ? "" : "\n") + token : token;
|
|
3519
3531
|
input.setDraft(cur);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-browser-cdp",
|
|
3
|
-
"version": "0.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",
|