From 1637a0e71c5e3e93f3488bd976415478c114a4e7 Mon Sep 17 00:00:00 2001 From: mt Date: Thu, 11 Jun 2026 09:50:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(copy):=20copyToClipboard=20=E5=A7=8B?= =?UTF-8?q?=E7=BB=88=E5=8F=91=E9=80=81=20postMessage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 copyToClipboard 内独立的 isInIframe 判断 - 改为始终调用 sendToParent,由 sendToParent 内部统一判断 iframe 环境 - 与 openSkillDialog 等其他 iframe 通信保持一致 --- frontend/src/lib/utils.ts | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts index 24730cf6..0775c9ae 100644 --- a/frontend/src/lib/utils.ts +++ b/frontend/src/lib/utils.ts @@ -18,29 +18,27 @@ export const externalLinkClassNoUnderline = "text-primary hover:underline"; * In iframe context, sends message to parent window to handle clipboard operation. */ export async function copyToClipboard(text: string): Promise { - const isInIframe = window.self !== window.top; const message = { type: POST_MESSAGE_TYPES.COPY_TO_CLIPBOARD, text, } as const; - if (isInIframe) { - try { - // Request parent window to copy - sendToParent(message); - console.log( - "[copyToClipboard] iframe mode → postMessage to parent", - message, - ); - return; - } catch (error) { - console.warn("[copyToClipboard] iframe postMessage failed", error); - } + console.log("[copyToClipboard] called, text length:", text.length); + + // 始终发送 postMessage,由 sendToParent 内部判断是否为 iframe 环境 + // 与 openSkillDialog 等其他 iframe 通信保持一致 + try { + sendToParent(message); + } catch { + // no-op } - // Direct clipboard access when not in iframe - console.log("[copyToClipboard] direct mode", message); - await navigator.clipboard.writeText(text); + // 同时也尝试直接写剪贴板(非 iframe 场景兜底) + try { + await navigator.clipboard.writeText(text); + } catch { + // no-op: 在 iframe 环境下由父窗口处理 + } } /**