dsh-browser-cdp 0.18.5 → 0.18.7

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