Skip to content

The open-source app everyone uses to manage agents at work

fix: copy button fallback for non-secure contexts (#2472)

Devin Foley26069682eea2
diff --git a/ui/src/components/CopyText.tsx b/ui/src/components/CopyText.tsx
index 61a6b34304..fc399fa044 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");