Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(desktop): 内嵌页面未真的加载时给出可重试错误界面 (#705)

hairyf5388f0c1195e
diff --git a/src-tauri/src/desktop/plugin_boot.js.inc b/src-tauri/src/desktop/plugin_boot.js.inc
index fc6e5c30..f749cb43 100644
--- a/src-tauri/src/desktop/plugin_boot.js.inc
+++ b/src-tauri/src/desktop/plugin_boot.js.inc
@@ -5,6 +5,7 @@
var stopped = false
var sawSplash = false
+ var reportedFrame = false
var stalledForCurrentSplash = false
var stalledTimer = null
var observer = null
@@ -90,6 +91,17 @@
stalledForCurrentSplash = false
}
+ // 帧身份申报(issue #705):宿主无法从 iframe 的 load 事件区分「dsh 页面已提交」与
+ // 「浏览器内部错误页已提交」——代理不可达等网络错误页同样触发 load,而错误页里永远
+ // 没有 #root。boot 页的 HTML 自带 #root,所以「子 frame 解析出 #root」是本 frame 正在
+ // 承载 dsh 文档的确证;宿主据此区分「页面真的加载了」与「帧里只有一张浏览器错误页」。
+ function reportFrame() {
+ if (reportedFrame) return
+ if (!rootNode()) return
+ reportedFrame = true
+ send('dsh://plugin-boot:frame')
+ }
+
function stop() {
if (stopped) return
stopped = true
@@ -100,6 +112,7 @@
}
function evaluate() {
+ reportFrame()
if (stopped) return
var failure = bootFailureText()
if (failure !== null) {
diff --git a/src-tauri/src/desktop/plugin_boot.rs b/src-tauri/src/desktop/plugin_boot.rs
index 6889d2cf..58959787 100644
--- a/src-tauri/src/desktop/plugin_boot.rs
+++ b/src-tauri/src/desktop/plugin_boot.rs
@@ -4,8 +4,12 @@
//! plugins 提示;普通页面正文出现同名文本不会触发。计时从 splash 首次被观察到
//! 才开始,消失后撤销,晚出现或再次出现都可重新计时;正常应用 shell 挂载后永久
//! 停止观察。
+//!
+//! 另有一条帧身份申报(issue #705):子 frame 解析出 `#root` 即上报
+//! `dsh://plugin-boot:frame`,宿主据此认定「帧里确实加载了 dsh 页面」而不是
+//! 浏览器内部错误页(错误页同样触发 iframe 的 load,且永远没有 `#root`)。
-/// iframe 内:报告 boot 页 stalled/ready;实际重载预算由宿主管理。
+/// iframe 内:报告帧身份与 boot 页 stalled/ready/failed;实际重载预算由宿主管理。
pub(crate) const PLUGIN_BOOT_RELOAD_JS: &str = include_str!("plugin_boot.js.inc");
#[cfg(test)]
@@ -22,6 +26,8 @@ mod tests {
assert!(PLUGIN_BOOT_RELOAD_JS.contains("dsh://plugin-boot:stalled"));
assert!(PLUGIN_BOOT_RELOAD_JS.contains("dsh://plugin-boot:ready"));
assert!(PLUGIN_BOOT_RELOAD_JS.contains("dsh://plugin-boot:failed"));
+ assert!(PLUGIN_BOOT_RELOAD_JS.contains("dsh://plugin-boot:frame"));
+ assert!(PLUGIN_BOOT_RELOAD_JS.contains("reportFrame"));
assert!(PLUGIN_BOOT_RELOAD_JS.contains("bootFailureText"));
assert!(PLUGIN_BOOT_RELOAD_JS.contains("Failed to load plugins"));
assert!(!PLUGIN_BOOT_RELOAD_JS.contains("body.innerText"));
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json
index 6ed0d71b..dd84faab 100644
--- a/src/i18n/locales/en-US.json
+++ b/src/i18n/locales/en-US.json
@@ -126,6 +126,7 @@
"ui.data_dir": "Data Directory",
"ui.iframe_error": "Cannot load the DeepSeek Harness interface.",
"ui.ensure_running": "Please make sure the service is running at {{url}}.",
+ "ui.iframe_unreachable_hint": "The service itself is running, but the embedded page never loaded. This is usually a system proxy or security tool blocking the request, or the page being redirected to an address that cannot be reached. Check your network/proxy settings, then retry.",
"ui.language": "Language",
"ui.languages.zh": "Chinese",
"ui.languages.en": "English",
diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json
index 5eabef5d..284bfb94 100644
--- a/src/i18n/locales/zh-CN.json
+++ b/src/i18n/locales/zh-CN.json
@@ -126,6 +126,7 @@
"ui.data_dir": "数据目录",
"ui.iframe_error": "无法加载 DeepSeek Harness 界面。",
"ui.ensure_running": "请确认服务正在 {{url}} 运行。",
+ "ui.iframe_unreachable_hint": "服务本身运行正常,但内嵌页面没有加载成功:通常是系统代理或安全软件拦截了页面请求,也可能是页面被跳转到了访问不到的地址。检查网络/代理设置后点击重试即可。",
"ui.language": "语言",
"ui.languages.zh": "中文",
"ui.languages.en": "English",
diff --git a/src/layout/components/iframe.tsx b/src/layout/components/iframe.tsx
index 32ff2ddc..ac5a6431 100644
--- a/src/layout/components/iframe.tsx
+++ b/src/layout/components/iframe.tsx
@@ -85,6 +85,9 @@ export function Iframe({ iframeRef }: IframeProps) {
// iframe → 宿主:iframe 自身的桥共用一个监听器,按 `data.type` 分发
useIframeMessage<IframeBridgeMessage>(iframeRef, (data) => {
+ // 能走到这里说明帧内确实跑着 dsh 页面(来源与 origin 已由 hook 校验过),
+ // 与具体桥无关——据此确认 iframe 不是一张浏览器内部错误页(issue #705)。
+ store.harness.markIframeAlive()
switch (data.type) {
// 原生通知:转发给 Tauri 命令弹出系统通知
case 'dsh://native-notification':
@@ -210,7 +213,12 @@ export function Iframe({ iframeRef }: IframeProps) {
title={t('ui.iframe_error')}
errorMsg={t('ui.ensure_running', { url: harness.serviceUrl })}
onRetry={store.harness.refreshIframe}
- />
+ >
+ {/* 服务就绪却毫无帧内消息:帧里根本没有 dsh 页面(浏览器内部错误页) */}
+ <If cond={harness.iframeErrorHint !== ''}>
+ <p className="text-xs leading-[18px] break-all text-load-muted">{harness.iframeErrorHint}</p>
+ </If>
+ </Loadable>
</div>
</If>
</div>
diff --git a/src/store/modules/harness/constants.ts b/src/store/modules/harness/constants.ts
index 0f1da246..29851d11 100644
--- a/src/store/modules/harness/constants.ts
+++ b/src/store/modules/harness/constants.ts
@@ -8,6 +8,16 @@
/** iframe 挂载后等待 dsh 页面完成加载的兜底上限 */
export const IFRAME_LOAD_TIMEOUT = 20000
+/**
+ * iframe 已触发 load、但帧内迟迟没有确认承载 dsh 文档时的宽限上限。
+ *
+ * 浏览器内部错误页(图省事的代理拦截、DNS 失败等)同样会触发 iframe 的 load,
+ * 而这类页面永远不会给出帧内消息(issue #705)。帧已提交后再等整个加载上限,
+ * 只会让用户多盯 20 秒的浏览器错误页,因此这里用一个远小于它的窗口尽快转为
+ * 可重试界面。必须大于插件 boot 桥的轮询间隔(1s),留出首次帧身份申报的时间。
+ */
+export const IFRAME_FRAME_GRACE_TIMEOUT = 5000
+
/** 健康探测退避区间(1s 起、1.5 倍递增、封顶 5s) */
export const HEALTH_PROBE_INITIAL_INTERVAL = 1000
export const HEALTH_PROBE_MAX_INTERVAL = 5000
diff --git a/src/store/modules/harness/store.ts b/src/store/modules/harness/store.ts
index d81362e6..04100efc 100644
--- a/src/store/modules/harness/store.ts
+++ b/src/store/modules/harness/store.ts
@@ -22,6 +22,7 @@ import { preinstall } from '../preinstall'
import { recovery } from '../recovery'
import { setting } from '../setting'
import {
+ IFRAME_FRAME_GRACE_TIMEOUT,
IFRAME_LOAD_TIMEOUT,
IFRAME_RECOVERY_ABSOLUTE_TIMEOUT,
IFRAME_RELOAD_MAX_ATTEMPTS,
@@ -98,6 +99,14 @@ export const harness = defineStore({
iframeSrc: '',
iframeLoaded: false,
iframeError: false,
+ /**
+ * 帧内已确认承载 dsh 文档(收到任一帧内桥消息)。
+ *
+ * iframe 的 load 事件不足以证明页面加载成功:浏览器内部错误页(代理拦截、
+ * DNS 失败等)同样触发 load,且永远不会发出帧内消息(issue #705)。因此页面
+ * 是否真的起来,只以「帧内自报」为准,load 只用来把判定窗口收紧。
+ */
+ iframeAlive: false,
iframeKey: 0,
serviceHealthy: false,
serviceRunning: false,
@@ -114,6 +123,13 @@ export const harness = defineStore({
showIframeError(): boolean {
return this.serviceHealthy && this.iframeError
},
+ /**
+ * 内嵌页面加载失败的补充说明:服务已就绪却没有任何帧内消息,说明帧里根本没
+ * 起来 dsh 页面(典型是一张浏览器内部错误页),而不是服务没跑起来。
+ */
+ iframeErrorHint(): string {
+ return this.iframeAlive ? '' : i18next.t('ui.iframe_unreachable_hint')
+ },
},
actions: {
/** 首次挂载时自动启动(StrictMode 重复挂载下保证只执行一次) */
@@ -195,6 +211,7 @@ export const harness = defineStore({
this.serviceHealthy = false
this.iframeLoaded = false
this.iframeError = false
+ this.iframeAlive = false
this.fail(message)
const error = await attachStartupDiagnostics(new Error(message), true)
@@ -247,6 +264,7 @@ export const harness = defineStore({
refreshIframe() {
this.iframeLoaded = false
this.iframeError = false
+ this.iframeAlive = false
if (iframeRefreshTimer !== undefined) {
clearTimeout(iframeRefreshTimer)
}
@@ -267,6 +285,11 @@ export const harness = defineStore({
this.iframeLoaded = false
},
+ /** 帧内任一桥消息到达:确认帧里确实跑着 dsh 页面(load 事件不算数,见 state 注释) */
+ markIframeAlive() {
+ this.iframeAlive = true
+ },
+
markIframeBootReady() {
iframeReloadGate.markReady()
if (iframeRefreshTimer !== undefined) {
@@ -418,6 +441,7 @@ export const harness = defineStore({
this.serviceHealthy = false
this.iframeLoaded = false
this.iframeError = false
+ this.iframeAlive = false
this.startupPhase = 'process-boot'
this.startupReason = i18next.t('status.loading_process')
try {
@@ -488,6 +512,7 @@ export const harness = defineStore({
this.serviceHealthy = false
this.iframeLoaded = false
this.iframeError = false
+ this.iframeAlive = false
// 重新启动/进入启动流程时先退出上一轮的错误与修复态(重启可能由插件修复、
// 配置切换触发),避免旧的「启动失败 / Preview」等信息在启动期间闪现。
// 注意:保留 attempts 计数,连续失败仍能命中「频繁失败」提示。
@@ -814,24 +839,35 @@ export const harness = defineStore({
},
})
-// 进入 ready 后 iframe 长时间未加载(dsh 未就绪/挂起)→ 转为错误界面,
-// 避免一直停在黑色加载遮罩
-let iframeLoadTimer: ReturnType<typeof setTimeout> | null = null
+// 进入 ready 后 iframe 始终没有自报「帧里跑着 dsh 页面」→ 转为错误界面,避免一直
+// 停在黑色加载遮罩。判定只看帧内自报,不看 load:浏览器内部错误页(代理拦截、DNS
+// 失败等)同样触发 load 却永远没有帧内消息,只按 load 判定就会把一张浏览器错误页
+// 当成加载成功——壳层既不给重试入口也不报错,用户只能重启电脑(issue #705)。
+let iframeWatch: { loaded: boolean, timer: ReturnType<typeof setTimeout> } | null = null
harness.$subscribe(() => {
- const { status, serviceHealthy, iframeLoaded, iframeError } = harness.$state
- if (status === 'ready' && serviceHealthy && !iframeLoaded && !iframeError) {
- if (!iframeLoadTimer) {
- iframeLoadTimer = setTimeout(() => {
- iframeLoadTimer = null
- harness.iframeLoaded = false
- harness.iframeError = true
- }, IFRAME_LOAD_TIMEOUT)
+ const { status, serviceHealthy, iframeLoaded, iframeAlive, iframeError } = harness.$state
+ const watching = status === 'ready' && serviceHealthy && !iframeAlive && !iframeError
+ if (!watching) {
+ if (iframeWatch) {
+ clearTimeout(iframeWatch.timer)
+ iframeWatch = null
}
+ return
}
- else {
- if (iframeLoadTimer) {
- clearTimeout(iframeLoadTimer)
- iframeLoadTimer = null
- }
+ // 帧已提交文档(load 已触发)却没有帧内消息:只剩「帧里是浏览器错误页」这种可能,
+ // 用远短于整体加载上限的宽限窗口尽快给出可重试界面。
+ if (iframeWatch?.loaded === iframeLoaded)
+ return
+ if (iframeWatch) {
+ clearTimeout(iframeWatch.timer)
+ }
+ iframeWatch = {
+ loaded: iframeLoaded,
+ timer: setTimeout(() => {
+ iframeWatch = null
+ console.warn('[Harness] iframe never confirmed a dsh document, showing retryable error')
+ harness.iframeLoaded = false
+ harness.iframeError = true
+ }, iframeLoaded ? IFRAME_FRAME_GRACE_TIMEOUT : IFRAME_LOAD_TIMEOUT),
}
})
diff --git a/test/iframe-watchdog.test.ts b/test/iframe-watchdog.test.ts
new file mode 100644
index 00000000..6ef1063d
--- /dev/null
+++ b/test/iframe-watchdog.test.ts
@@ -0,0 +1,121 @@
+import { readFileSync } from 'node:fs'
+import i18next from 'i18next'
+import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
+import { resources } from '../src/i18n/index.resource'
+
+vi.mock('@tauri-apps/api/core', () => ({ invoke: vi.fn() }))
+vi.mock('@tauri-apps/api/event', () => ({ listen: vi.fn(async () => vi.fn()) }))
+vi.mock('@/config/client', () => ({ queryClient: { invalidateQueries: vi.fn() } }))
+vi.mock('../src/store/modules/harness-updater', () => ({
+ harnessUpdater: { checkForUpdate: vi.fn() },
+}))
+
+const { harness } = await import('../src/store/modules/harness')
+const { IFRAME_FRAME_GRACE_TIMEOUT, IFRAME_LOAD_TIMEOUT } = await import('../src/store/modules/harness/constants')
+
+function locale(file: 'zh-CN.json' | 'en-US.json'): Record<string, string> {
+ const raw = readFileSync(new URL(`../src/i18n/locales/${file}`, import.meta.url), 'utf8')
+ return JSON.parse(raw) as Record<string, string>
+}
+
+/**
+ * 摆出「服务已就绪、iframe 已挂载」的状态并等观察者落地。
+ *
+ * valtio 的订阅回调在微任务里批处理,状态变更后必须放一个 tick,看门狗才会按新
+ * 状态重新计时(`advanceTimersByTimeAsync` 同时推进真实微任务)。
+ */
+async function mountIframe(overrides: Record<string, unknown> = {}) {
+ Object.assign(harness, {
+ status: 'ready',
+ serviceHealthy: true,
+ serviceRunning: true,
+ iframeLoaded: false,
+ iframeError: false,
+ iframeAlive: false,
+ busyAction: null,
+ ...overrides,
+ })
+ await vi.advanceTimersByTimeAsync(0)
+}
+
+beforeAll(async () => {
+ // 与壳层同一份资源初始化默认 i18next 实例:断言的是真实译文,而不是未初始化时的 key 回退
+ await i18next.init({
+ resources,
+ lng: 'zh-CN',
+ keySeparator: false,
+ nsSeparator: false,
+ initAsync: false,
+ })
+})
+
+beforeEach(async () => {
+ vi.useFakeTimers()
+ await mountIframe({ serviceHealthy: false, iframeLoaded: true, iframeError: true })
+})
+
+afterEach(() => {
+ vi.useRealTimers()
+})
+
+describe('iframe dsh document watchdog', () => {
+ // issue #705:浏览器内部错误页(代理拦截、DNS 失败等)同样触发 iframe 的 load,
+ // 只按 load 判定就会把它当成加载成功,用户看不到任何重试入口。
+ it('shows the retryable error screen when the frame commits a document but never reports a dsh page', async () => {
+ await mountIframe({ iframeLoaded: true })
+
+ await vi.advanceTimersByTimeAsync(IFRAME_FRAME_GRACE_TIMEOUT - 1)
+ expect(harness.iframeError).toBe(false)
+
+ await vi.advanceTimersByTimeAsync(1)
+ expect(harness.iframeError).toBe(true)
+ expect(harness.iframeLoaded).toBe(false)
+ })
+
+ it('falls back to the full load deadline when the frame never commits a document at all', async () => {
+ await mountIframe()
+
+ await vi.advanceTimersByTimeAsync(IFRAME_LOAD_TIMEOUT - 1)
+ expect(harness.iframeError).toBe(false)
+
+ await vi.advanceTimersByTimeAsync(1)
+ expect(harness.iframeError).toBe(true)
+ })
+
+ it('never shows the error screen while the frame reports a live dsh page', async () => {
+ await mountIframe()
+ harness.markIframeAlive()
+
+ await vi.advanceTimersByTimeAsync(IFRAME_LOAD_TIMEOUT + IFRAME_FRAME_GRACE_TIMEOUT)
+ expect(harness.iframeError).toBe(false)
+ })
+
+ it('requires a fresh frame report after the retry remounts the iframe', async () => {
+ await mountIframe({ iframeAlive: true, iframeLoaded: true })
+
+ harness.refreshIframe()
+ await vi.advanceTimersByTimeAsync(0)
+ expect(harness.iframeAlive).toBe(false)
+
+ await vi.advanceTimersByTimeAsync(800)
+ await mountIframe({ iframeLoaded: true })
+ await vi.advanceTimersByTimeAsync(IFRAME_FRAME_GRACE_TIMEOUT)
+ expect(harness.iframeError).toBe(true)
+ })
+
+ it('explains the failure only when the frame never reported a dsh page', async () => {
+ await mountIframe({ iframeError: true })
+ expect(harness.iframeErrorHint).toBe(locale('zh-CN.json')['ui.iframe_unreachable_hint'])
+
+ harness.markIframeAlive()
+ await vi.advanceTimersByTimeAsync(0)
+ expect(harness.iframeErrorHint).toBe('')
+ })
+})
+
+describe('iframe unreachable i18n contract', () => {
+ it('defines the unreachable hint in both locales', () => {
+ expect(locale('zh-CN.json')['ui.iframe_unreachable_hint']).toBeTypeOf('string')
+ expect(locale('en-US.json')['ui.iframe_unreachable_hint']).toBeTypeOf('string')
+ })
+})
diff --git a/test/plugin-boot.test.ts b/test/plugin-boot.test.ts
index 819f82a5..a53dfdc6 100644
--- a/test/plugin-boot.test.ts
+++ b/test/plugin-boot.test.ts
@@ -2,7 +2,12 @@ import { readFileSync } from 'node:fs'
import { runInNewContext } from 'node:vm'
import { afterEach, describe, expect, it, vi } from 'vitest'
-type PageState = 'empty' | 'splash' | 'chat' | 'normal'
+type PageState = 'empty' | 'splash' | 'chat' | 'normal' | 'mounting'
+
+interface BootHarnessOptions {
+ /** 模拟顶层文档(非 iframe):脚本必须整体不工作 */
+ topFrame?: boolean
+}
interface BootHarness {
messages: string[]
@@ -14,7 +19,10 @@ const script = readFileSync(
'utf8',
)
-function createHarness(initialState: PageState): BootHarness {
+/** 帧身份申报(子 frame 解析出 `#root` 后必然先于其它消息到达一次)。 */
+const FRAME_REPORT = 'dsh://plugin-boot:frame'
+
+function createHarness(initialState: PageState, options: BootHarnessOptions = {}): BootHarness {
let state = initialState
let mutationCallback = () => {}
const messages: string[] = []
@@ -87,11 +95,13 @@ function createHarness(initialState: PageState): BootHarness {
addEventListener() {},
removeEventListener() {},
}
+ if (options.topFrame)
+ window.top = window
runInNewContext(script, {
window,
document: {
documentElement: {},
- getElementById: () => root,
+ getElementById: () => (state === 'mounting' ? null : root),
},
MutationObserver: FakeMutationObserver,
setTimeout,
@@ -119,13 +129,13 @@ describe('plugin boot bridge', () => {
const harness = createHarness('empty')
vi.advanceTimersByTime(20_000)
- expect(harness.messages).toEqual([])
+ expect(harness.messages).toEqual([FRAME_REPORT])
harness.setState('splash')
vi.advanceTimersByTime(7_999)
- expect(harness.messages).toEqual([])
+ expect(harness.messages).toEqual([FRAME_REPORT])
vi.advanceTimersByTime(1)
- expect(harness.messages).toEqual(['dsh://plugin-boot:stalled'])
+ expect(harness.messages).toEqual([FRAME_REPORT, 'dsh://plugin-boot:stalled'])
})
it('resets the deadline when the splash disappears and rearms on reappearance', () => {
@@ -135,26 +145,59 @@ describe('plugin boot bridge', () => {
vi.advanceTimersByTime(4_000)
harness.setState('empty')
vi.advanceTimersByTime(10_000)
- expect(harness.messages).toEqual([])
+ expect(harness.messages).toEqual([FRAME_REPORT])
harness.setState('splash')
vi.advanceTimersByTime(8_000)
- expect(harness.messages).toEqual(['dsh://plugin-boot:stalled'])
+ expect(harness.messages).toEqual([FRAME_REPORT, 'dsh://plugin-boot:stalled'])
})
it('ignores matching page text and permanently disarms after the app shell mounts', () => {
vi.useFakeTimers()
const chat = createHarness('chat')
vi.advanceTimersByTime(20_000)
- expect(chat.messages).toEqual([])
+ expect(chat.messages).toEqual([FRAME_REPORT])
const harness = createHarness('splash')
vi.advanceTimersByTime(2_000)
harness.setState('normal')
- expect(harness.messages).toEqual(['dsh://plugin-boot:ready'])
+ expect(harness.messages).toEqual([FRAME_REPORT, 'dsh://plugin-boot:ready'])
harness.setState('splash')
vi.advanceTimersByTime(20_000)
- expect(harness.messages).toEqual(['dsh://plugin-boot:ready'])
+ expect(harness.messages).toEqual([FRAME_REPORT, 'dsh://plugin-boot:ready'])
+ })
+
+ it('reports one frame identity once the document exposes the dsh mount point', () => {
+ vi.useFakeTimers()
+ const harness = createHarness('mounting')
+
+ vi.advanceTimersByTime(3_000)
+ expect(harness.messages).toEqual([])
+
+ harness.setState('splash')
+ expect(harness.messages).toEqual([FRAME_REPORT])
+
+ // 身份只申报一次;卡在 splash 时后续消息仍是原有的 stalled
+ vi.advanceTimersByTime(8_000)
+ expect(harness.messages).toEqual([FRAME_REPORT, 'dsh://plugin-boot:stalled'])
+ })
+
+ // issue #705:浏览器内部错误页(代理拦截、DNS 失败等)同样会触发 iframe 的 load,
+ // 但永远没有 #root。脚本在这里保持沉默,宿主才能把「没收到帧身份」判成加载失败。
+ it('never reports a frame identity while the frame has no dsh mount point', () => {
+ vi.useFakeTimers()
+ const harness = createHarness('mounting')
+
+ vi.advanceTimersByTime(60_000)
+ expect(harness.messages).toEqual([])
+ })
+
+ it('stays silent in the top-level document', () => {
+ vi.useFakeTimers()
+ const harness = createHarness('normal', { topFrame: true })
+
+ vi.advanceTimersByTime(60_000)
+ expect(harness.messages).toEqual([])
})
})