fix(copy): copyToClipboard 始终发送 postMessage
- 移除 copyToClipboard 内独立的 isInIframe 判断 - 改为始终调用 sendToParent,由 sendToParent 内部统一判断 iframe 环境 - 与 openSkillDialog 等其他 iframe 通信保持一致
This commit is contained in:
parent
03ff3ece7f
commit
1637a0e71c
@ -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<void> {
|
||||
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 环境下由父窗口处理
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user