Conversation
自定义协议下 location.origin 不能当 WebSocket base 用:官方 Electron 壳把页面 放在 dsh-app://app/,它的 host 是字面量 app,于是 /sidebar/ws/* 解析成 ws://app/...,DNS 永远解析不了 —— 终端的、agent-terminals、agent-opens、 fs-watch 四条 socket 全部连不上(控制台只见连接失败,功能静默退化)。 改为读 __DSH_TRANSPORT__.streamBaseUrl(DSH 自己的 downlink mux 用的同一来源), 普通 http(s) 页面回退 document.baseURI,行为不变。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
桌面壳(官方 Electron 壳)把页面放在自定义协议下:
dsh-app://app/。此时location.origin是dsh-app://app,而它的host是字面量字符串app—— 不是网络主机。插件用
new URL('/sidebar/ws/…', location.origin)再换协议来拼 WebSocket 地址,于是得到ws://app/sidebar/ws/…,DNS 永远解析不了。受影响的 socket:/sidebar/ws/agent-opens(src/client/sidebar/use-host-feeds.ts)/sidebar/ws/fs-watch(src/client/use-dir-watch.ts)表现是控制台持续刷连接失败、功能静默退化(这两处的重连都有退避,最终会自停,所以用户只会看到报错而看不出功能已失效)。
证据
同一个页面里实测三种构造:
new URL('/api/remote.mux', __DSH_TRANSPORT__.streamBaseUrl)(DSH 自己的 mux)ws://127.0.0.1:19388/api/remote.muxnew URL('/sidebar/ws/agent-opens', __DSH_TRANSPORT__.streamBaseUrl)(本次改法)ws://127.0.0.1:19388/sidebar/ws/agent-opensnew URL('/sidebar/ws/agent-opens', location.origin)(现状)ws://app/sidebar/ws/agent-opensDSH 自己并不用
location.origin:packages/api/gateway/src/client/stream-client.ts的remoteStreamUrl()读的是globalThis.__DSH_TRANSPORT__?.streamBaseUrl ?? document.baseURI,注释写明「A shell-owned Host on another origin supplies that base through the transport」。原代码那句「Same construction the app's own downlink WebSockets use」的前提因此不成立。改动
新增
sidebarWebSocketBase()(放在src/client/desktop-env.ts—— 该模块本就只负责报告壳提供的事实),两处 socket 构造改用它:普通 http(s) 页面下
document.baseURI与原location.origin等价,行为不变;仅在壳提供了__DSH_TRANSPORT__.streamBaseUrl时改用真实 Host 地址。验证
ws://app/...连接失败。pnpm typecheck通过;pnpm test1138 passed。一处与本改动无关的本地失败:
tests/plugin-meta.spec.ts的 “actually packs the icon and locales into the tarball” 在 Windows 上失败 ——tar -tzf输出 CRLF,断言按\n分割后每项带\r(得到'package/LICENSE\r'),于是'package/icon.svg'匹配不上。该 spec 其余 5 个用例正常,本次未改动该 spec 与package.json。