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.
|
* In iframe context, sends message to parent window to handle clipboard operation.
|
||||||
*/
|
*/
|
||||||
export async function copyToClipboard(text: string): Promise<void> {
|
export async function copyToClipboard(text: string): Promise<void> {
|
||||||
const isInIframe = window.self !== window.top;
|
|
||||||
const message = {
|
const message = {
|
||||||
type: POST_MESSAGE_TYPES.COPY_TO_CLIPBOARD,
|
type: POST_MESSAGE_TYPES.COPY_TO_CLIPBOARD,
|
||||||
text,
|
text,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
if (isInIframe) {
|
console.log("[copyToClipboard] called, text length:", text.length);
|
||||||
|
|
||||||
|
// 始终发送 postMessage,由 sendToParent 内部判断是否为 iframe 环境
|
||||||
|
// 与 openSkillDialog 等其他 iframe 通信保持一致
|
||||||
try {
|
try {
|
||||||
// Request parent window to copy
|
|
||||||
sendToParent(message);
|
sendToParent(message);
|
||||||
console.log(
|
} catch {
|
||||||
"[copyToClipboard] iframe mode → postMessage to parent",
|
// no-op
|
||||||
message,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
} catch (error) {
|
|
||||||
console.warn("[copyToClipboard] iframe postMessage failed", error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Direct clipboard access when not in iframe
|
// 同时也尝试直接写剪贴板(非 iframe 场景兜底)
|
||||||
console.log("[copyToClipboard] direct mode", message);
|
try {
|
||||||
await navigator.clipboard.writeText(text);
|
await navigator.clipboard.writeText(text);
|
||||||
|
} catch {
|
||||||
|
// no-op: 在 iframe 环境下由父窗口处理
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user