diff --git a/ui/src/components/CopyText.tsx b/ui/src/components/CopyText.tsx index 61a6b343..fc399fa0 100644 --- a/ui/src/components/CopyText.tsx +++ b/ui/src/components/CopyText.tsx @@ -18,7 +18,23 @@ export function CopyText({ text, children, className, copiedLabel = "Copied!" }: const handleClick = useCallback(async () => { try { - await navigator.clipboard.writeText(text); + if (navigator.clipboard && window.isSecureContext) { + await navigator.clipboard.writeText(text); + } else { + // Fallback for non-secure contexts (e.g. HTTP on non-localhost) + const textarea = document.createElement("textarea"); + textarea.value = text; + textarea.style.position = "fixed"; + textarea.style.left = "-9999px"; + document.body.appendChild(textarea); + try { + textarea.select(); + const success = document.execCommand("copy"); + if (!success) throw new Error("execCommand copy failed"); + } finally { + document.body.removeChild(textarea); + } + } setLabel(copiedLabel); } catch { setLabel("Copy failed");