dsh-chrome-bridge 1.16.2 → 1.16.3
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-chrome-bridge",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.3",
|
|
4
4
|
"description": "DSH plugin: native browser_* tools that drive the Chrome you are already using, over native messaging + CDP. No WebSocket, no port, no Connect button. The native host and the MV3 extension ship inside this package and are installed automatically on first load; the one step left is adding the DSH Bridge extension to Chrome, from the Chrome Web Store or as the bundled unpacked copy. Until then browser_* tools fail loudly with those exact steps.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/setup.js
CHANGED
|
@@ -70,7 +70,7 @@ export function paths(home = os.homedir(), platform = process.platform) {
|
|
|
70
70
|
home,
|
|
71
71
|
bridge,
|
|
72
72
|
hostDir,
|
|
73
|
-
// Chrome
|
|
73
|
+
// Chrome 拉起宿主用的脚本:装的时候现写(Windows run.bat,其余 run.sh),写进 DSH 自己的 node
|
|
74
74
|
launcher: path.join(hostDir, win ? 'run.bat' : 'run.sh'),
|
|
75
75
|
extDir,
|
|
76
76
|
chromeDir,
|
|
@@ -186,6 +186,48 @@ export function winLauncher(execPath = process.execPath, electron = Boolean(proc
|
|
|
186
186
|
].join('\r\n')
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
/** 单引号包起来给 sh 用(路径里的单引号拆开转义) */
|
|
190
|
+
const shQuote = (s) => `'${String(s).replace(/'/g, `'\\''`)}'`
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* macOS / Linux 的宿主启动脚本。Chrome 拉起宿主时 PATH 很干净:nvm / fnm / volta / asdf / mise 装的 node 都不在里面,
|
|
194
|
+
* 只按固定路径找的话这些用户一装就连不上(issue #2)。所以和 Windows 一样,先用装的时候 DSH 自己的 node
|
|
195
|
+
* (桌面版是 Electron,要 ELECTRON_RUN_AS_NODE);DSH 升级换了路径,插件下次加载会重写这个文件。
|
|
196
|
+
* 那个 node 没了再按固定路径和常见的版本管理器目录找;都找不到就把原因写进 launch-error.txt,DSH 报错时读出来给人看
|
|
197
|
+
* (Chrome 那边只知道「断开了」,stderr 谁也看不到)。
|
|
198
|
+
*/
|
|
199
|
+
export function unixLauncher(execPath = process.execPath, electron = Boolean(process.versions.electron)) {
|
|
200
|
+
return [
|
|
201
|
+
'#!/bin/sh',
|
|
202
|
+
'# Chrome 通过这个脚本拉起原生宿主。浏览器桥插件装的时候现写的,别手改(DSH 下次加载会重写)。',
|
|
203
|
+
'',
|
|
204
|
+
'HERE="$(cd "$(dirname "$0")" && pwd)"',
|
|
205
|
+
'ERR="$HERE/launch-error.txt"',
|
|
206
|
+
`DSH_NODE=${shQuote(execPath)}`,
|
|
207
|
+
'go() { N="$1"; shift; rm -f "$ERR"; exec "$N" "$HERE/host.js" "$@"; }',
|
|
208
|
+
'',
|
|
209
|
+
'if [ -n "$DSH_BRIDGE_NODE" ] && [ -x "$DSH_BRIDGE_NODE" ]; then go "$DSH_BRIDGE_NODE" "$@"; fi',
|
|
210
|
+
`if [ -x "$DSH_NODE" ]; then ${electron ? 'export ELECTRON_RUN_AS_NODE=1; ' : ''}go "$DSH_NODE" "$@"; fi`,
|
|
211
|
+
'',
|
|
212
|
+
'for N in /usr/local/bin/node "$HOME/.local/bin/node" /opt/homebrew/bin/node /usr/bin/node \\',
|
|
213
|
+
' "$HOME/.volta/bin/node" "$HOME/.asdf/shims/node" "$HOME/.local/share/mise/shims/node"; do',
|
|
214
|
+
' if [ -x "$N" ]; then go "$N" "$@"; fi',
|
|
215
|
+
'done',
|
|
216
|
+
'for N in "$HOME"/.nvm/versions/node/*/bin/node; do',
|
|
217
|
+
' if [ -x "$N" ]; then LAST="$N"; fi',
|
|
218
|
+
'done',
|
|
219
|
+
'if [ -n "$LAST" ]; then go "$LAST" "$@"; fi',
|
|
220
|
+
'N="$(command -v node 2>/dev/null)"',
|
|
221
|
+
'if [ -n "$N" ]; then go "$N" "$@"; fi',
|
|
222
|
+
'',
|
|
223
|
+
'MSG="找不到可用的 node:装插件时 DSH 用的 $DSH_NODE 已经不在了,常见位置也都没有。重启一次 DSH 会按它现在用的 node 重写启动脚本。"',
|
|
224
|
+
'echo "$MSG" > "$ERR" 2>/dev/null',
|
|
225
|
+
'echo "dsh-bridge: $MSG" >&2',
|
|
226
|
+
'exit 1',
|
|
227
|
+
'',
|
|
228
|
+
].join('\n')
|
|
229
|
+
}
|
|
230
|
+
|
|
189
231
|
/** 装好了没有(只看落盘结果,不管 Chrome 有没有加载扩展)。 */
|
|
190
232
|
export function installState(home = os.homedir()) {
|
|
191
233
|
const p = paths(home)
|
|
@@ -243,18 +285,20 @@ export function ensureInstalled(options = {}) {
|
|
|
243
285
|
|
|
244
286
|
let nmPrev = null
|
|
245
287
|
try { nmPrev = fs.readFileSync(p.nmFile, 'utf8') } catch {}
|
|
246
|
-
const launcherBody = win ? winLauncher() :
|
|
288
|
+
const launcherBody = win ? winLauncher() : unixLauncher()
|
|
247
289
|
let launcherPrev = null
|
|
248
|
-
|
|
249
|
-
const
|
|
250
|
-
const upToDate = prev === stamp && nmPrev === nmBody &&
|
|
290
|
+
try { launcherPrev = fs.readFileSync(p.launcher, 'utf8') } catch {}
|
|
291
|
+
const regOk = !win || REG_KEYS.every((k) => regValue(k) === p.nmFile)
|
|
292
|
+
const upToDate = prev === stamp && nmPrev === nmBody && launcherPrev === launcherBody && regOk
|
|
293
|
+
&& allPresent(vExt, p.extDir) && allPresent(vHost, p.hostDir)
|
|
251
294
|
if (!upToDate) {
|
|
252
295
|
fs.mkdirSync(p.extDir, { recursive: true })
|
|
253
296
|
fs.cpSync(vExt, p.extDir, { recursive: true, force: true })
|
|
254
297
|
fs.mkdirSync(p.hostDir, { recursive: true })
|
|
255
298
|
fs.cpSync(vHost, p.hostDir, { recursive: true, force: true })
|
|
256
|
-
|
|
257
|
-
|
|
299
|
+
fs.writeFileSync(p.launcher, launcherBody)
|
|
300
|
+
if (!win) fs.chmodSync(p.launcher, 0o755)
|
|
301
|
+
fs.rmSync(path.join(p.hostDir, 'launch-error.txt'), { force: true }) // 上回拉不起来的原因:脚本重写了就作废
|
|
258
302
|
fs.mkdirSync(p.nmDir, { recursive: true })
|
|
259
303
|
fs.writeFileSync(p.nmFile, nmBody)
|
|
260
304
|
if (win) {
|
|
@@ -312,6 +356,9 @@ export function installHint(home = os.homedir()) {
|
|
|
312
356
|
'重启一次 DSH 会再试一遍;还不行就在 GitHub 提 issue。',
|
|
313
357
|
].join('\n')
|
|
314
358
|
}
|
|
359
|
+
let launchErr = ''
|
|
360
|
+
try { launchErr = fs.readFileSync(path.join(s.hostDir, 'launch-error.txt'), 'utf8').trim() } catch {}
|
|
361
|
+
if (launchErr) return `Chrome 拉起宿主失败:${launchErr}\n重启 DSH 之后,完全退出 Chrome 再打开一次。`
|
|
315
362
|
if (s.store) {
|
|
316
363
|
return [
|
|
317
364
|
`扩展已经从 Chrome 应用商店装好了(DSH Bridge ${s.store.version}),但宿主没连上:`,
|
|
@@ -168,11 +168,6 @@ code { font: 500 12.5px var(--mono); letter-spacing: -0.2px; }
|
|
|
168
168
|
.hero-title small:empty { display: none; }
|
|
169
169
|
|
|
170
170
|
.explain { margin: 12px 2px 8px; font-size: 12.5px; color: var(--label-2); line-height: 1.5; }
|
|
171
|
-
.cmd {
|
|
172
|
-
display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; border-radius: 14px; background: var(--fill);
|
|
173
|
-
}
|
|
174
|
-
.cmd code { flex: 1; min-width: 0; font-size: 12.5px; color: var(--label); }
|
|
175
|
-
.cmd .link { padding: 4px 10px; border-radius: 10px; background: var(--glass-hi); }
|
|
176
171
|
|
|
177
172
|
.chain { display: flex; align-items: flex-start; margin-top: 14px; padding: 12px 4px 0; border-top: 0.5px solid var(--sep); }
|
|
178
173
|
.node { flex: 1; min-width: 0; text-align: center; }
|
|
@@ -116,8 +116,7 @@ function renderStatus(st) {
|
|
|
116
116
|
let mood, icon, title, sub, extra = ''
|
|
117
117
|
if (!st.connected) {
|
|
118
118
|
mood = 'bad'; icon = 'bang'; title = '没连上本地宿主'; sub = 'DSH 现在用不了浏览器'
|
|
119
|
-
extra = `<p class="explain"
|
|
120
|
-
<div class="cmd"><code>dsh-chrome-bridge update</code><button class="link" type="button" data-act="copyCmd">复制</button></div>`
|
|
119
|
+
extra = `<p class="explain">多半是 DSH 里还没装浏览器桥插件,或者装好后还没重启 DSH。装好、重启 DSH 后点右上角重新连接;还连不上就在 DSH 里让它用一下浏览器,它会说卡在哪一步。</p>`
|
|
121
120
|
} else if (st.paused) {
|
|
122
121
|
mood = 'warn'; icon = 'pause'; title = '已暂停'; sub = 'DSH 现在动不了你的浏览器'
|
|
123
122
|
} else {
|
|
@@ -336,9 +335,6 @@ document.addEventListener('click', async (ev) => {
|
|
|
336
335
|
render(await ask('releaseAll'))
|
|
337
336
|
toast('全部松手了')
|
|
338
337
|
break
|
|
339
|
-
case 'copyCmd':
|
|
340
|
-
copy('dsh-chrome-bridge update', '命令已复制,去终端粘贴运行')
|
|
341
|
-
break
|
|
342
338
|
case 'diagnostics': {
|
|
343
339
|
const r = await ask('diagnostics')
|
|
344
340
|
if (r && r.text) copy(r.text, '诊断信息已复制,可以直接发给开发者')
|