dsh-browser-cdp 0.18.9 → 0.18.10

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.9",
5
+ "version": "0.18.10",
6
6
  "manifestVersion": "0.15",
7
7
  "facets": {
8
8
  "host": {
package/lib/client.js CHANGED
@@ -288,7 +288,8 @@ var watchEn = {
288
288
  linksLocalRow: "Local Chrome (managed)",
289
289
  linksLocalEnableHint: "Checked = auto mode may fall back to the managed local browser when the activated target is unreachable",
290
290
  pickCardTitle: "Browser picks",
291
- pickCardElements: "{n} element(s) picked"
291
+ pickCardElements: "{n} element(s) picked",
292
+ pickCardRemove: "Remove these picks"
292
293
  };
293
294
  var watchDict = {
294
295
  en: watchEn,
@@ -376,7 +377,8 @@ var watchDict = {
376
377
  linksLocalRow: "本机 Chrome(受管启动)",
377
378
  linksLocalEnableHint: "勾选 = 允许 auto 模式在激活目标不可达时回落本机启动",
378
379
  pickCardTitle: "浏览器点选内容",
379
- pickCardElements: "已选 {n} 个元素"
380
+ pickCardElements: "已选 {n} 个元素",
381
+ pickCardRemove: "移除这段点选"
380
382
  }
381
383
  };
382
384
  function wt(key, params = void 0) {
@@ -1854,7 +1856,7 @@ function FamLinks(props) {
1854
1856
  function apply(ctx) {
1855
1857
  mountFamilySettingsCard(ctx);
1856
1858
  mountPluginsPageCard(ctx);
1857
- mountComposerDecoration(ctx);
1859
+ mountPicksDockCard(ctx);
1858
1860
  var betterSidebarService;
1859
1861
  try {
1860
1862
  betterSidebarService = typeof ctx.get === "function" ? ctx.get("betterSidebar") : void 0;
@@ -3101,22 +3103,53 @@ var TAB_CSS = `
3101
3103
  * {"cdpEndpoint":..., "targetId":..., "pageUrl":..., "elements":[{n,backendNodeId,tag,id,name,focusable,describe}]}
3102
3104
  * [/CDP-PICKS]
3103
3105
  */
3104
- function mountComposerDecoration(ctx) {
3105
- var cards = [];
3106
- var lastSig = "";
3107
- var diag = {
3108
- stage: "init",
3109
- error: "",
3110
- anchor: false,
3111
- cards: 0,
3112
- draftLen: -1
3113
- };
3106
+ function CdpPicksDockCard(props) {
3107
+ var input = props.input;
3108
+ var h = React.createElement;
3109
+ var setTick = React.useState(0)[1];
3110
+ React.useEffect(function() {
3111
+ var timer = window.setInterval(function() {
3112
+ setTick(function(n) {
3113
+ return n + 1;
3114
+ });
3115
+ }, 1e3);
3116
+ return function() {
3117
+ window.clearInterval(timer);
3118
+ };
3119
+ }, []);
3120
+ var snap = input && input.state && input.state.getSnapshot ? input.state.getSnapshot() : null;
3121
+ var draft = snap && typeof snap.draft === "string" ? snap.draft : "";
3122
+ var re = /\[(?:🌐 )?CDP-PICKS page="([^"]*)" targetId="([^"]*)" endpoint="([^"]*)"\]\n([\s\S]*?)\n\[\/CDP-PICKS\]/g;
3123
+ var found = [], mm;
3124
+ while ((mm = re.exec(draft)) !== null) {
3125
+ var elements = [];
3126
+ try {
3127
+ var obj = JSON.parse(mm[4]);
3128
+ elements = obj && obj.elements || [];
3129
+ } catch (e) {}
3130
+ found.push({
3131
+ title: mm[1],
3132
+ endpoint: mm[3],
3133
+ elements,
3134
+ block: mm[0]
3135
+ });
3136
+ }
3114
3137
  try {
3115
- window.__dshBrowserCdpDeco = diag;
3138
+ window.__dshBrowserCdpDeco = {
3139
+ stage: found.length ? "rendered" : "no-blocks",
3140
+ blocks: found.length,
3141
+ draftLen: draft.length
3142
+ };
3116
3143
  } catch (e) {}
3117
- var CARD_STYLE = {
3118
- position: "fixed",
3119
- zIndex: "9998",
3144
+ function removeBlock(block) {
3145
+ if (!input || typeof input.setDraft !== "function") return;
3146
+ var idx = draft.indexOf(block);
3147
+ if (idx < 0) return;
3148
+ var next = draft.slice(0, idx) + draft.slice(idx + block.length);
3149
+ next = next.replace(/^\s*\n+/, "").replace(/\n+\s*$/, "");
3150
+ input.setDraft(next);
3151
+ }
3152
+ var cardStyle = {
3120
3153
  display: "grid",
3121
3154
  gap: "4px",
3122
3155
  padding: "8px 10px",
@@ -3126,17 +3159,15 @@ function mountComposerDecoration(ctx) {
3126
3159
  background: "var(--dsw-alias-bg-surface, rgba(127,127,127,.14))",
3127
3160
  border: "1px solid var(--dsw-alias-border-l2, rgba(127,127,127,.35))",
3128
3161
  borderRadius: "12px",
3129
- boxShadow: "0 8px 24px rgba(0,0,0,.18)",
3130
- boxSizing: "border-box",
3131
- pointerEvents: "auto"
3162
+ boxSizing: "border-box"
3132
3163
  };
3133
- var HEAD_STYLE = {
3164
+ var headStyle = {
3134
3165
  display: "flex",
3135
3166
  alignItems: "center",
3136
3167
  gap: "6px",
3137
3168
  flexWrap: "wrap"
3138
3169
  };
3139
- var SUB_STYLE = {
3170
+ var subStyle = {
3140
3171
  fontSize: "11px",
3141
3172
  color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.75))",
3142
3173
  overflow: "hidden",
@@ -3144,7 +3175,7 @@ function mountComposerDecoration(ctx) {
3144
3175
  whiteSpace: "nowrap",
3145
3176
  minWidth: 0
3146
3177
  };
3147
- var CHIP_STYLE = {
3178
+ var chipStyle = {
3148
3179
  display: "flex",
3149
3180
  alignItems: "baseline",
3150
3181
  gap: "6px",
@@ -3154,159 +3185,75 @@ function mountComposerDecoration(ctx) {
3154
3185
  borderRadius: "8px",
3155
3186
  minWidth: 0
3156
3187
  };
3157
- var NUM_STYLE = {
3188
+ var numStyle = {
3158
3189
  fontWeight: 700,
3159
3190
  flex: "0 0 auto",
3160
3191
  color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.75))"
3161
3192
  };
3162
- var TAG_STYLE = {
3193
+ var tagStyle = {
3163
3194
  fontWeight: 600,
3164
3195
  flex: "0 0 auto"
3165
3196
  };
3166
- var DESC_STYLE = {
3197
+ var descStyle = {
3167
3198
  overflow: "hidden",
3168
3199
  textOverflow: "ellipsis",
3169
3200
  whiteSpace: "nowrap",
3170
3201
  minWidth: 0
3171
3202
  };
3172
- function hide() {
3173
- for (var i = 0; i < cards.length; i++) {
3174
- var el = cards[i];
3175
- if (el && el.parentNode) el.parentNode.removeChild(el);
3176
- }
3177
- cards = [];
3178
- diag.cards = 0;
3179
- }
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;
3185
- }
3186
- function composerEl() {
3187
- var selectors = [
3188
- "[data-composer-input]",
3189
- "[contenteditable=\"true\"]",
3190
- "textarea"
3191
- ];
3192
- for (var s = 0; s < selectors.length; s++) {
3193
- var list = document.querySelectorAll(selectors[s]);
3194
- var best = null, bestBottom = -1;
3195
- for (var i = 0; i < list.length; i++) {
3196
- var r = list[i].getBoundingClientRect();
3197
- if (r.width < 120 || r.height < 32) continue;
3198
- if (r.top > window.innerHeight || r.bottom < 0) continue;
3199
- if (r.bottom > bestBottom) {
3200
- bestBottom = r.bottom;
3201
- best = list[i];
3202
- }
3203
- }
3204
- if (best) return best;
3205
- }
3206
- return null;
3207
- }
3208
- function render(pageTitle, endpoint, elements) {
3209
- var comp = composerEl();
3210
- if (!comp) {
3211
- diag.stage = "no-composer";
3212
- diag.anchor = false;
3213
- hide();
3214
- return;
3215
- }
3216
- diag.anchor = true;
3217
- var rect = comp.getBoundingClientRect();
3218
- hide();
3219
- var card = document.createElement("div");
3220
- card.setAttribute("data-dsh-cdp-picks-card", "");
3221
- var cs = card.style;
3222
- for (var k in CARD_STYLE) cs[k] = CARD_STYLE[k];
3223
- card.style.left = Math.max(8, rect.left) + "px";
3224
- card.style.width = Math.min(Math.max(rect.width, 240), 620) + "px";
3225
- card.style.bottom = Math.max(8, window.innerHeight - rect.top + 8) + "px";
3226
- card.style.maxHeight = "40vh";
3227
- card.style.overflowY = "auto";
3228
- var head = el2("div", HEAD_STYLE);
3229
- head.appendChild(el2("span", { fontWeight: 700 }, "🌐 " + wt("pickCardTitle")));
3230
- head.appendChild(el2("span", SUB_STYLE, (endpoint || "") + " · " + (pageTitle || "")));
3231
- head.appendChild(el2("span", SUB_STYLE, wt("pickCardElements", { n: elements.length })));
3232
- card.appendChild(head);
3233
- var limit = Math.min(elements.length, 6);
3234
- for (var i = 0; i < limit; i++) {
3235
- var el = elements[i] || {};
3236
- var chip = el2("div", CHIP_STYLE);
3237
- chip.appendChild(el2("span", NUM_STYLE, "#" + (el.n || i + 1)));
3238
- chip.appendChild(el2("span", TAG_STYLE, el.tag || "?"));
3239
- chip.appendChild(el2("span", DESC_STYLE, el.describe || el.name || ""));
3240
- card.appendChild(chip);
3241
- }
3242
- if (elements.length > 6) card.appendChild(el2("div", SUB_STYLE, "… +" + (elements.length - 6)));
3243
- document.body.appendChild(card);
3244
- cards.push(card);
3245
- diag.cards = cards.length;
3246
- diag.stage = "rendered";
3247
- }
3248
- function tick() {
3249
- diag.stage = "tick";
3250
- try {
3251
- var sid = currentSessionId(ctx.sessions.list.getSnapshot());
3252
- if (!sid) {
3253
- diag.stage = "no-session";
3254
- if (lastSig !== "") {
3255
- lastSig = "";
3256
- hide();
3257
- }
3258
- return;
3259
- }
3260
- var conversation = ctx.get("conversation");
3261
- if (!conversation || !conversation.input) {
3262
- diag.stage = "no-conversation";
3263
- return;
3264
- }
3265
- var actx = ctx.sessions.scope(sid);
3266
- if (!actx) {
3267
- diag.stage = "no-scope";
3268
- return;
3269
- }
3270
- var input = conversation.input.for(actx);
3271
- var snap = input && input.state && input.state.getSnapshot ? input.state.getSnapshot() : null;
3272
- var draft = snap && typeof snap.draft === "string" ? snap.draft : "";
3273
- diag.draftLen = draft.length;
3274
- if (draft === lastSig) {
3275
- diag.stage = "same-draft";
3276
- return;
3203
+ var closeStyle = {
3204
+ marginLeft: "auto",
3205
+ flex: "0 0 auto",
3206
+ font: "inherit",
3207
+ fontSize: "12px",
3208
+ cursor: "pointer",
3209
+ border: "none",
3210
+ background: "none",
3211
+ color: "var(--dsw-alias-label-tertiary, rgba(127,127,127,.75))",
3212
+ padding: "0 2px"
3213
+ };
3214
+ return h("div", { style: {
3215
+ display: "grid",
3216
+ gap: "6px"
3217
+ } }, found.map(function(f) {
3218
+ var head = h("div", { style: headStyle }, h("span", { style: { fontWeight: 700 } }, "🌐 " + wt("pickCardTitle")), h("span", { style: subStyle }, (f.endpoint || "") + " · " + (f.title || "")), h("span", { style: subStyle }, wt("pickCardElements", { n: f.elements.length })), h("button", {
3219
+ type: "button",
3220
+ title: wt("pickCardRemove"),
3221
+ style: closeStyle,
3222
+ onClick: function() {
3223
+ removeBlock(f.block);
3277
3224
  }
3278
- lastSig = draft;
3279
- var re = /\[(?:🌐 )?CDP-PICKS page="([^"]*)" targetId="([^"]*)" endpoint="([^"]*)"\]\n([\s\S]*?)\n\[\/CDP-PICKS\]/g;
3280
- var found = [], mm;
3281
- while ((mm = re.exec(draft)) !== null) {
3282
- var elements = [];
3225
+ }, "✕"));
3226
+ var chips = f.elements.slice(0, 6).map(function(el) {
3227
+ return h("div", {
3228
+ key: el.n,
3229
+ style: chipStyle
3230
+ }, h("span", { style: numStyle }, "#" + (el.n || "")), h("span", { style: tagStyle }, el.tag || "?"), h("span", { style: descStyle }, el.describe || el.name || ""));
3231
+ });
3232
+ if (f.elements.length > 6) chips.push(h("div", { style: subStyle }, "… +" + (f.elements.length - 6)));
3233
+ return h("div", {
3234
+ key: f.targetId + ":" + f.endpoint,
3235
+ style: cardStyle
3236
+ }, head, chips);
3237
+ }));
3238
+ }
3239
+ function mountPicksDockCard(ctx) {
3240
+ ctx.slots.inject("conversation.input.dock", function() {
3241
+ return ctx.slots.register({
3242
+ name: "conversation.input.dock",
3243
+ id: "dsh-browser-cdp.picks",
3244
+ order: 0,
3245
+ inject: function(sessionId) {
3246
+ var input = null;
3283
3247
  try {
3284
- var obj = JSON.parse(mm[4]);
3285
- elements = obj && obj.elements || [];
3286
- } catch (e) {}
3287
- found.push({
3288
- title: mm[1],
3289
- endpoint: mm[3],
3290
- elements
3291
- });
3292
- }
3293
- if (found.length === 0) {
3294
- diag.stage = "no-blocks";
3295
- hide();
3296
- return;
3248
+ var actx = ctx.sessions.scope(sessionId);
3249
+ input = actx.get("conversation").input.for(actx);
3250
+ } catch (e) {
3251
+ input = null;
3252
+ }
3253
+ return { input };
3297
3254
  }
3298
- for (var i = 0; i < found.length; i++) render(found[i].title, found[i].endpoint, found[i].elements);
3299
- } catch (e) {
3300
- diag.stage = "error";
3301
- diag.error = String(e && e.message || e);
3302
- }
3303
- }
3304
- var timer = window.setInterval(tick, 1e3);
3305
- tick();
3306
- return function() {
3307
- window.clearInterval(timer);
3308
- hide();
3309
- };
3255
+ }, CdpPicksDockCard);
3256
+ }, "dsh-browser-cdp: picks dock card");
3310
3257
  }
3311
3258
  function currentSessionId(list) {
3312
3259
  if (!list || typeof list !== "object") return "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-browser-cdp",
3
- "version": "0.18.9",
3
+ "version": "0.18.10",
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",