From f910ab292dfce3dac252a3ea9cccc25b5aec5f1d Mon Sep 17 00:00:00 2001 From: Pine Date: Mon, 7 Sep 2026 18:27:23 +0800 Subject: [PATCH] =?UTF-8?q?debug:=20=E5=A4=96=E9=93=BE=E8=B0=83=E8=B5=B7?= =?UTF-8?q?=E8=AF=8A=E6=96=AD=E9=9D=A2=E6=9D=BF+=E5=85=A8=E9=93=BE?= =?UTF-8?q?=E8=B7=AF=E6=97=A5=E5=BF=97=EF=BC=88=E4=B8=B4=E6=97=B6=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 桌面左上角固定调试面板:显示 tauri/osPath/pywebview/pathname 环境判定, 三个按钮分别走 openExternalLink(百度/白名单资讯)与 openInAppWebView; 面板内实时展示最近日志。关键链路埋点 [ext-debug]: openExternalLink 判定 → openInAppWebView → osRouteStore.openApp → osWindowStore.open(含当前窗口列表)→ WebPage mount。 --- console/src/components/ExternalLinkDebug.tsx | 122 +++++++++++++++++++ console/src/os/DesktopOS.tsx | 6 +- console/src/os/osRouteStore.ts | 1 + console/src/os/osWindowStore.ts | 1 + console/src/pages/portal/Web/WebPage.tsx | 6 +- console/src/utils/openExternalLink.ts | 15 ++- 6 files changed, 145 insertions(+), 6 deletions(-) create mode 100644 console/src/components/ExternalLinkDebug.tsx diff --git a/console/src/components/ExternalLinkDebug.tsx b/console/src/components/ExternalLinkDebug.tsx new file mode 100644 index 0000000..c34d292 --- /dev/null +++ b/console/src/components/ExternalLinkDebug.tsx @@ -0,0 +1,122 @@ +/** + * ExternalLinkDebug.tsx — 外链调起调试面板(临时诊断用)。 + * + * 固定在桌面左上角,展示当前环境判定与最近日志;三个测试按钮分别走 + * openExternalLink / openInAppWebView,逐段确认容器为何无法调起。 + */ +import { useCallback, useState } from "react"; +import { + openExternalLink, + openInAppWebView, + isDesktopTauriRuntime, +} from "../../utils/openExternalLink"; +import { isOsPath } from "../../utils/navigationMode"; +import { getPyWebViewApi } from "../../utils/pywebview"; + +const TEST_URL = "https://www.baidu.com"; +const TRUST_URL = "https://news.infoepoch.cn"; + +export default function ExternalLinkDebug() { + const [logs, setLogs] = useState([]); + const [collapsed, setCollapsed] = useState(false); + + const log = useCallback((msg: string) => { + console.log(`[ext-debug] ${msg}`); + setLogs((prev) => [...prev.slice(-14), msg]); + }, []); + + const env = (() => { + let pywebview = false; + try { + pywebview = !!getPyWebViewApi()?.open_external_link; + } catch { + /* ignore */ + } + return { + tauri: isDesktopTauriRuntime(), + osPath: isOsPath(window.location.pathname), + pathname: window.location.pathname, + pywebview, + }; + })(); + + const run = (fn: () => void, label: string) => { + log(`▶ ${label} url=${TEST_URL}`); + try { + fn(); + log(" 调用已同步返回(异步结果见后续日志)"); + } catch (e) { + log(` ✗ 同步抛错: ${String(e)}`); + } + }; + + return ( +
+
+ 外链调试 + +
+ {!collapsed && ( + <> +
+
tauri={String(env.tauri)} osPath={String(env.osPath)} pywebview={String(env.pywebview)}
+
path={env.pathname}
+
+
+ + + +
+
+ {logs.length === 0 ? ( +
(暂无日志,点击上方按钮)
+ ) : ( + logs.map((l, i) => ( +
+ {l} +
+ )) + )} +
+ + )} +
+ ); +} diff --git a/console/src/os/DesktopOS.tsx b/console/src/os/DesktopOS.tsx index 4b08c61..7edb321 100644 --- a/console/src/os/DesktopOS.tsx +++ b/console/src/os/DesktopOS.tsx @@ -30,6 +30,7 @@ import { isAgentAvailableInChat } from "../utils/agentVisibility"; import { purgeAppState, removePluginAppState } from "./osCleanup"; import WindowFrame from "./WindowFrame"; import WindowRouter from "./WindowRouter"; +import ExternalLinkDebug from "../components/ExternalLinkDebug"; import { baseFromRoutePath } from "./osRouteMap"; import MenuBar from "./MenuBar"; import Dock from "./Dock"; @@ -477,7 +478,7 @@ export default function DesktopOS() { - + } > @@ -544,6 +545,9 @@ export default function DesktopOS() { {wpOpen && setWpOpen(false)} />} {booting && } + + {/* 外链调起调试面板(诊断用,临时) */} + ); } diff --git a/console/src/os/osRouteStore.ts b/console/src/os/osRouteStore.ts index 8ad865c..d53786b 100644 --- a/console/src/os/osRouteStore.ts +++ b/console/src/os/osRouteStore.ts @@ -40,6 +40,7 @@ export const useOsRoute = create((set) => ({ targets: {}, openApp: (routeId, path) => { + console.log("[ext-debug] osRouteStore.openApp", JSON.stringify({ routeId, path })); if (path !== undefined) { set((s) => ({ targets: { diff --git a/console/src/os/osWindowStore.ts b/console/src/os/osWindowStore.ts index 53f4708..3c39f11 100644 --- a/console/src/os/osWindowStore.ts +++ b/console/src/os/osWindowStore.ts @@ -187,6 +187,7 @@ export const useOsWindows = create()( open: (id, size) => { const state = get(); + console.log("[ext-debug] osWindowStore.open", JSON.stringify({ id, exists: !!state.windows[id], openIds: Object.keys(state.windows) })); if (state.windows[id]) { // Already open — restore if minimized, then focus. set((s) => ({ diff --git a/console/src/pages/portal/Web/WebPage.tsx b/console/src/pages/portal/Web/WebPage.tsx index bb93132..cca06f7 100644 --- a/console/src/pages/portal/Web/WebPage.tsx +++ b/console/src/pages/portal/Web/WebPage.tsx @@ -34,7 +34,11 @@ export default function WebPage() { const location = useLocation(); const close = useOsWindows((s) => s.close); const navigate = useNavigate(); - const [targetUrl, setTargetUrl] = useState(() => parseWebUrl(location.search)); + const [targetUrl, setTargetUrl] = useState(() => { + const u = parseWebUrl(location.search); + console.log("[ext-debug] WebPage mount", JSON.stringify({ search: location.search, url: u })); + return u; + }); // 白名单标识:unknown(判定中)/ trusted / third-party const [trust, setTrust] = useState<"unknown" | "trusted" | "third-party">("unknown"); const [loading, setLoading] = useState(true); diff --git a/console/src/utils/openExternalLink.ts b/console/src/utils/openExternalLink.ts index e62d985..329b3ea 100644 --- a/console/src/utils/openExternalLink.ts +++ b/console/src/utils/openExternalLink.ts @@ -127,6 +127,7 @@ export function openExternalLink( const fullUrl = resolveSupportedExternalUrl(url); if (!fullUrl) { + console.warn("[ext-debug] openExternalLink: 非支持协议,已忽略", url); return; } @@ -134,14 +135,19 @@ export function openExternalLink( // forceSystem=true 时(容器内「系统浏览器打开」)跳过接管。 try { const proto = new URL(fullUrl).protocol; - const isDesktopShell = - isDesktopTauriRuntime() || isOsPath(window.location.pathname); + const tauri = isDesktopTauriRuntime(); + const osPath = isOsPath(window.location.pathname); + const isDesktopShell = tauri || osPath; + console.log( + "[ext-debug] openExternalLink 判定", + JSON.stringify({ url, fullUrl, proto, tauri, osPath, isDesktopShell, forceSystem }), + ); if (!forceSystem && HTTP_PROTOCOLS.has(proto) && isDesktopShell) { openInAppWebView(fullUrl); return; } - } catch { - /* fall through */ + } catch (e) { + console.warn("[ext-debug] openExternalLink 判定异常", e); } const runtime = detectExternalLinkRuntime(fullUrl); @@ -168,6 +174,7 @@ export function openExternalLink( export function openInAppWebView(fullUrl: string): void { try { const path = `/webpage?url=${encodeURIComponent(fullUrl)}`; + console.log("[ext-debug] openInAppWebView → openApp", JSON.stringify({ routeId: "core.web-view", path })); useOsRoute.getState().openApp("core.web-view", path); } catch (e) { console.warn("[external-link] in-app web view open failed", e);