dsh-browser-cdp 0.18.6 → 0.18.8
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/dsh-plugin.json +1 -1
- package/lib/client.js +139 -112
- package/package.json +1 -1
package/dsh-plugin.json
CHANGED
package/lib/client.js
CHANGED
|
@@ -193,7 +193,9 @@ function bindSnapshotSelector(source) {
|
|
|
193
193
|
const inject = [
|
|
194
194
|
"slots",
|
|
195
195
|
"locale",
|
|
196
|
-
"connection"
|
|
196
|
+
"connection",
|
|
197
|
+
"sessions",
|
|
198
|
+
"conversation"
|
|
197
199
|
];
|
|
198
200
|
var _egoLocale = (function() {
|
|
199
201
|
try {
|
|
@@ -284,7 +286,9 @@ var watchEn = {
|
|
|
284
286
|
linksDisabledHint: "Disabled — enable it before activating",
|
|
285
287
|
linksActivate: "activate",
|
|
286
288
|
linksLocalRow: "Local Chrome (managed)",
|
|
287
|
-
linksLocalEnableHint: "Checked = auto mode may fall back to the managed local browser when the activated target is unreachable"
|
|
289
|
+
linksLocalEnableHint: "Checked = auto mode may fall back to the managed local browser when the activated target is unreachable",
|
|
290
|
+
pickCardTitle: "Browser picks",
|
|
291
|
+
pickCardElements: "{n} element(s) picked"
|
|
288
292
|
};
|
|
289
293
|
var watchDict = {
|
|
290
294
|
en: watchEn,
|
|
@@ -370,7 +374,9 @@ var watchDict = {
|
|
|
370
374
|
linksDisabledHint: "已停用——先勾选启用才能激活",
|
|
371
375
|
linksActivate: "激活",
|
|
372
376
|
linksLocalRow: "本机 Chrome(受管启动)",
|
|
373
|
-
linksLocalEnableHint: "勾选 = 允许 auto 模式在激活目标不可达时回落本机启动"
|
|
377
|
+
linksLocalEnableHint: "勾选 = 允许 auto 模式在激活目标不可达时回落本机启动",
|
|
378
|
+
pickCardTitle: "浏览器点选内容",
|
|
379
|
+
pickCardElements: "已选 {n} 个元素"
|
|
374
380
|
}
|
|
375
381
|
};
|
|
376
382
|
function wt(key, params = void 0) {
|
|
@@ -3098,130 +3104,138 @@ var TAB_CSS = `
|
|
|
3098
3104
|
function mountComposerDecoration(ctx) {
|
|
3099
3105
|
var cards = [];
|
|
3100
3106
|
var lastSig = "";
|
|
3107
|
+
var diag = {
|
|
3108
|
+
stage: "init",
|
|
3109
|
+
error: "",
|
|
3110
|
+
anchor: false,
|
|
3111
|
+
cards: 0,
|
|
3112
|
+
draftLen: -1
|
|
3113
|
+
};
|
|
3114
|
+
try {
|
|
3115
|
+
window.__dshBrowserCdpDeco = diag;
|
|
3116
|
+
} catch (e) {}
|
|
3117
|
+
var CARD_STYLE = {
|
|
3118
|
+
position: "fixed",
|
|
3119
|
+
zIndex: "9998",
|
|
3120
|
+
display: "grid",
|
|
3121
|
+
gap: "4px",
|
|
3122
|
+
padding: "8px 10px",
|
|
3123
|
+
font: "inherit",
|
|
3124
|
+
fontSize: "12px",
|
|
3125
|
+
color: "var(--dsw-alias-label-primary, inherit)",
|
|
3126
|
+
background: "var(--dsw-alias-bg-surface, rgba(127,127,127,.14))",
|
|
3127
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))",
|
|
3128
|
+
borderRadius: "12px",
|
|
3129
|
+
boxShadow: "0 8px 24px rgba(0,0,0,.18)",
|
|
3130
|
+
boxSizing: "border-box",
|
|
3131
|
+
pointerEvents: "auto"
|
|
3132
|
+
};
|
|
3133
|
+
var HEAD_STYLE = {
|
|
3134
|
+
display: "flex",
|
|
3135
|
+
alignItems: "center",
|
|
3136
|
+
gap: "6px",
|
|
3137
|
+
flexWrap: "wrap"
|
|
3138
|
+
};
|
|
3139
|
+
var SUB_STYLE = {
|
|
3140
|
+
fontSize: "11px",
|
|
3141
|
+
color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.75))",
|
|
3142
|
+
overflow: "hidden",
|
|
3143
|
+
textOverflow: "ellipsis",
|
|
3144
|
+
whiteSpace: "nowrap",
|
|
3145
|
+
minWidth: 0
|
|
3146
|
+
};
|
|
3147
|
+
var CHIP_STYLE = {
|
|
3148
|
+
display: "flex",
|
|
3149
|
+
alignItems: "baseline",
|
|
3150
|
+
gap: "6px",
|
|
3151
|
+
padding: "3px 8px",
|
|
3152
|
+
background: "var(--dsw-alias-bg-module-platform, rgba(127,127,127,.1))",
|
|
3153
|
+
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.22))",
|
|
3154
|
+
borderRadius: "8px",
|
|
3155
|
+
minWidth: 0
|
|
3156
|
+
};
|
|
3157
|
+
var NUM_STYLE = {
|
|
3158
|
+
fontWeight: 700,
|
|
3159
|
+
flex: "0 0 auto",
|
|
3160
|
+
color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.75))"
|
|
3161
|
+
};
|
|
3162
|
+
var TAG_STYLE = {
|
|
3163
|
+
fontWeight: 600,
|
|
3164
|
+
flex: "0 0 auto"
|
|
3165
|
+
};
|
|
3166
|
+
var DESC_STYLE = {
|
|
3167
|
+
overflow: "hidden",
|
|
3168
|
+
textOverflow: "ellipsis",
|
|
3169
|
+
whiteSpace: "nowrap",
|
|
3170
|
+
minWidth: 0
|
|
3171
|
+
};
|
|
3101
3172
|
function hide() {
|
|
3102
3173
|
for (var i = 0; i < cards.length; i++) {
|
|
3103
3174
|
var el = cards[i];
|
|
3104
|
-
el && el.parentNode
|
|
3175
|
+
if (el && el.parentNode) el.parentNode.removeChild(el);
|
|
3105
3176
|
}
|
|
3106
3177
|
cards = [];
|
|
3178
|
+
diag.cards = 0;
|
|
3107
3179
|
}
|
|
3108
|
-
function
|
|
3109
|
-
var
|
|
3110
|
-
if (
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
function cardStyle() {
|
|
3114
|
-
return {
|
|
3115
|
-
display: "grid",
|
|
3116
|
-
gap: "4px",
|
|
3117
|
-
margin: "0 0 6px",
|
|
3118
|
-
padding: "8px 10px",
|
|
3119
|
-
font: "inherit",
|
|
3120
|
-
fontSize: "12px",
|
|
3121
|
-
color: "var(--dsw-alias-label-primary, inherit)",
|
|
3122
|
-
background: "var(--dsw-alias-bg-module-platform, rgba(127,127,127,.08))",
|
|
3123
|
-
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.3))",
|
|
3124
|
-
borderRadius: "12px",
|
|
3125
|
-
boxSizing: "border-box",
|
|
3126
|
-
width: "100%"
|
|
3127
|
-
};
|
|
3180
|
+
function el2(tag, style, text) {
|
|
3181
|
+
var el = document.createElement(tag);
|
|
3182
|
+
if (style) for (var k in style) el.style[k] = style[k];
|
|
3183
|
+
if (text !== void 0 && text !== null && text !== "") el.textContent = String(text);
|
|
3184
|
+
return el;
|
|
3128
3185
|
}
|
|
3129
|
-
function
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
background: "var(--dsw-alias-bg-module-platform, rgba(127,127,127,.1))",
|
|
3136
|
-
border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.22))",
|
|
3137
|
-
borderRadius: "8px",
|
|
3138
|
-
minWidth: 0
|
|
3139
|
-
};
|
|
3186
|
+
function composerEl() {
|
|
3187
|
+
var el = document.querySelector("[data-composer-input]");
|
|
3188
|
+
if (!el) el = document.querySelector("[data-composer-input] [contenteditable=\"true\"]");
|
|
3189
|
+
if (!el) el = document.querySelector("[contenteditable=\"true\"]");
|
|
3190
|
+
if (!el) el = document.querySelector("textarea");
|
|
3191
|
+
return el;
|
|
3140
3192
|
}
|
|
3141
|
-
function render(pageTitle, endpoint,
|
|
3142
|
-
var
|
|
3143
|
-
if (!
|
|
3193
|
+
function render(pageTitle, endpoint, elements) {
|
|
3194
|
+
var comp = composerEl();
|
|
3195
|
+
if (!comp) {
|
|
3196
|
+
diag.stage = "no-composer";
|
|
3197
|
+
diag.anchor = false;
|
|
3144
3198
|
hide();
|
|
3145
3199
|
return;
|
|
3146
3200
|
}
|
|
3201
|
+
diag.anchor = true;
|
|
3202
|
+
var rect = comp.getBoundingClientRect();
|
|
3147
3203
|
hide();
|
|
3148
|
-
var h = React.createElement;
|
|
3149
|
-
var head = h("div", { style: {
|
|
3150
|
-
display: "flex",
|
|
3151
|
-
alignItems: "center",
|
|
3152
|
-
gap: "6px",
|
|
3153
|
-
flexWrap: "wrap"
|
|
3154
|
-
} }, h("span", { style: badgeLike() }, "🌐"), h("span", { style: { fontWeight: 600 } }, wt("pickCardTitle")), h("span", { style: {
|
|
3155
|
-
color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.75))",
|
|
3156
|
-
overflow: "hidden",
|
|
3157
|
-
textOverflow: "ellipsis",
|
|
3158
|
-
whiteSpace: "nowrap",
|
|
3159
|
-
minWidth: 0
|
|
3160
|
-
} }, (endpoint || "") + " · " + (pageTitle || pageUrl || "")), h("span", { style: {
|
|
3161
|
-
color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.75))",
|
|
3162
|
-
flex: "0 0 auto"
|
|
3163
|
-
} }, wt("pickCardElements", { n: elements.length })));
|
|
3164
|
-
var chips = elements.slice(0, 6).map(function(el) {
|
|
3165
|
-
return h("div", {
|
|
3166
|
-
key: el.n,
|
|
3167
|
-
style: chipStyle()
|
|
3168
|
-
}, h("span", { style: {
|
|
3169
|
-
fontWeight: 700,
|
|
3170
|
-
flex: "0 0 auto",
|
|
3171
|
-
color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.75))"
|
|
3172
|
-
} }, "#" + el.n), h("span", { style: {
|
|
3173
|
-
fontWeight: 600,
|
|
3174
|
-
flex: "0 0 auto"
|
|
3175
|
-
} }, el.tag || "?"), h("span", { style: {
|
|
3176
|
-
overflow: "hidden",
|
|
3177
|
-
textOverflow: "ellipsis",
|
|
3178
|
-
whiteSpace: "nowrap",
|
|
3179
|
-
minWidth: 0
|
|
3180
|
-
} }, el.describe || el.name || ""));
|
|
3181
|
-
});
|
|
3182
|
-
if (elements.length > 6) chips.push(h("div", { style: {
|
|
3183
|
-
fontSize: "11px",
|
|
3184
|
-
color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.7))"
|
|
3185
|
-
} }, "… +" + (elements.length - 6)));
|
|
3186
3204
|
var card = document.createElement("div");
|
|
3187
3205
|
card.setAttribute("data-dsh-cdp-picks-card", "");
|
|
3188
|
-
var
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3206
|
+
var cs = card.style;
|
|
3207
|
+
for (var k in CARD_STYLE) cs[k] = CARD_STYLE[k];
|
|
3208
|
+
card.style.left = Math.max(8, rect.left) + "px";
|
|
3209
|
+
card.style.width = Math.min(Math.max(rect.width, 240), 620) + "px";
|
|
3210
|
+
card.style.bottom = Math.max(8, window.innerHeight - rect.top + 8) + "px";
|
|
3211
|
+
card.style.maxHeight = "40vh";
|
|
3212
|
+
card.style.overflowY = "auto";
|
|
3213
|
+
var head = el2("div", HEAD_STYLE);
|
|
3214
|
+
head.appendChild(el2("span", { fontWeight: 700 }, "🌐 " + wt("pickCardTitle")));
|
|
3215
|
+
head.appendChild(el2("span", SUB_STYLE, (endpoint || "") + " · " + (pageTitle || "")));
|
|
3216
|
+
head.appendChild(el2("span", SUB_STYLE, wt("pickCardElements", { n: elements.length })));
|
|
3217
|
+
card.appendChild(head);
|
|
3218
|
+
var limit = Math.min(elements.length, 6);
|
|
3219
|
+
for (var i = 0; i < limit; i++) {
|
|
3220
|
+
var el = elements[i] || {};
|
|
3221
|
+
var chip = el2("div", CHIP_STYLE);
|
|
3222
|
+
chip.appendChild(el2("span", NUM_STYLE, "#" + (el.n || i + 1)));
|
|
3223
|
+
chip.appendChild(el2("span", TAG_STYLE, el.tag || "?"));
|
|
3224
|
+
chip.appendChild(el2("span", DESC_STYLE, el.describe || el.name || ""));
|
|
3225
|
+
card.appendChild(chip);
|
|
3193
3226
|
}
|
|
3194
|
-
if (
|
|
3195
|
-
|
|
3196
|
-
anchor.insertBefore(card, anchor.firstChild);
|
|
3227
|
+
if (elements.length > 6) card.appendChild(el2("div", SUB_STYLE, "… +" + (elements.length - 6)));
|
|
3228
|
+
document.body.appendChild(card);
|
|
3197
3229
|
cards.push(card);
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
return {
|
|
3201
|
-
fontSize: "12px",
|
|
3202
|
-
lineHeight: "16px"
|
|
3203
|
-
};
|
|
3204
|
-
}
|
|
3205
|
-
function renderToDom(vdom) {
|
|
3206
|
-
if (vdom === null || vdom === void 0 || vdom === false) return document.createTextNode("");
|
|
3207
|
-
if (typeof vdom === "string" || typeof vdom === "number") return document.createTextNode(String(vdom));
|
|
3208
|
-
if (Array.isArray(vdom)) {
|
|
3209
|
-
var frag = document.createDocumentFragment();
|
|
3210
|
-
for (var i = 0; i < vdom.length; i++) frag.appendChild(renderToDom(vdom[i]));
|
|
3211
|
-
return frag;
|
|
3212
|
-
}
|
|
3213
|
-
var el = document.createElement(vdom.type || "div");
|
|
3214
|
-
var props = vdom.props || {};
|
|
3215
|
-
if (props.style) for (var k in props.style) el.style[k] = props.style[k];
|
|
3216
|
-
if (props.key) el.setAttribute("data-key", String(props.key));
|
|
3217
|
-
var children = props.children;
|
|
3218
|
-
el.appendChild(renderToDom(children === void 0 ? null : children));
|
|
3219
|
-
return el;
|
|
3230
|
+
diag.cards = cards.length;
|
|
3231
|
+
diag.stage = "rendered";
|
|
3220
3232
|
}
|
|
3221
3233
|
function tick() {
|
|
3234
|
+
diag.stage = "tick";
|
|
3222
3235
|
try {
|
|
3223
3236
|
var sid = currentSessionId(ctx.sessions.list.getSnapshot());
|
|
3224
3237
|
if (!sid) {
|
|
3238
|
+
diag.stage = "no-session";
|
|
3225
3239
|
if (lastSig !== "") {
|
|
3226
3240
|
lastSig = "";
|
|
3227
3241
|
hide();
|
|
@@ -3229,13 +3243,23 @@ function mountComposerDecoration(ctx) {
|
|
|
3229
3243
|
return;
|
|
3230
3244
|
}
|
|
3231
3245
|
var conversation = ctx.get("conversation");
|
|
3232
|
-
if (!conversation || !conversation.input)
|
|
3246
|
+
if (!conversation || !conversation.input) {
|
|
3247
|
+
diag.stage = "no-conversation";
|
|
3248
|
+
return;
|
|
3249
|
+
}
|
|
3233
3250
|
var actx = ctx.sessions.scope(sid);
|
|
3234
|
-
if (!actx)
|
|
3251
|
+
if (!actx) {
|
|
3252
|
+
diag.stage = "no-scope";
|
|
3253
|
+
return;
|
|
3254
|
+
}
|
|
3235
3255
|
var input = conversation.input.for(actx);
|
|
3236
3256
|
var snap = input && input.state && input.state.getSnapshot ? input.state.getSnapshot() : null;
|
|
3237
3257
|
var draft = snap && typeof snap.draft === "string" ? snap.draft : "";
|
|
3238
|
-
|
|
3258
|
+
diag.draftLen = draft.length;
|
|
3259
|
+
if (draft === lastSig) {
|
|
3260
|
+
diag.stage = "same-draft";
|
|
3261
|
+
return;
|
|
3262
|
+
}
|
|
3239
3263
|
lastSig = draft;
|
|
3240
3264
|
var re = /\[(?:🌐 )?CDP-PICKS page="([^"]*)" targetId="([^"]*)" endpoint="([^"]*)"\]\n([\s\S]*?)\n\[\/CDP-PICKS\]/g;
|
|
3241
3265
|
var found = [], mm;
|
|
@@ -3247,17 +3271,20 @@ function mountComposerDecoration(ctx) {
|
|
|
3247
3271
|
} catch (e) {}
|
|
3248
3272
|
found.push({
|
|
3249
3273
|
title: mm[1],
|
|
3250
|
-
targetId: mm[2],
|
|
3251
3274
|
endpoint: mm[3],
|
|
3252
3275
|
elements
|
|
3253
3276
|
});
|
|
3254
3277
|
}
|
|
3255
3278
|
if (found.length === 0) {
|
|
3279
|
+
diag.stage = "no-blocks";
|
|
3256
3280
|
hide();
|
|
3257
3281
|
return;
|
|
3258
3282
|
}
|
|
3259
|
-
for (var i = 0; i < found.length; i++) render(found[i].title, found[i].endpoint, found[i].
|
|
3260
|
-
} catch (e) {
|
|
3283
|
+
for (var i = 0; i < found.length; i++) render(found[i].title, found[i].endpoint, found[i].elements);
|
|
3284
|
+
} catch (e) {
|
|
3285
|
+
diag.stage = "error";
|
|
3286
|
+
diag.error = String(e && e.message || e);
|
|
3287
|
+
}
|
|
3261
3288
|
}
|
|
3262
3289
|
var timer = window.setInterval(tick, 1e3);
|
|
3263
3290
|
tick();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-browser-cdp",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.8",
|
|
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",
|