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 环境下由父窗口处理 + } } /**