From 545aecfe92466d0d5bcf589427b6a42771ae244f Mon Sep 17 00:00:00 2001 From: Roland Tannous Date: Fri, 10 Apr 2026 05:09:15 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20copy=20button=20fails=20on=20plain=20HTT?= =?UTF-8?q?P=20=E2=80=94=20use=20execCommand=20fallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontend/src/features/chat/chat-page.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/studio/frontend/src/features/chat/chat-page.tsx b/studio/frontend/src/features/chat/chat-page.tsx index f378264017..3195ff8402 100644 --- a/studio/frontend/src/features/chat/chat-page.tsx +++ b/studio/frontend/src/features/chat/chat-page.tsx @@ -101,10 +101,24 @@ function HighlightedSnippet({ ); const handleCopy = useCallback(() => { - navigator.clipboard.writeText(source).then(() => { + // navigator.clipboard requires HTTPS or localhost — Studio is often + // served over plain HTTP on a LAN IP, so fall back to execCommand. + try { + if (navigator.clipboard && window.isSecureContext) { + navigator.clipboard.writeText(source); + } else { + const ta = document.createElement("textarea"); + ta.value = source; + ta.style.position = "fixed"; + ta.style.left = "-9999px"; + document.body.appendChild(ta); + ta.select(); + document.execCommand("copy"); + document.body.removeChild(ta); + } setCopied(true); setTimeout(() => setCopied(false), 2000); - }); + } catch { /* ignore */ } }, [source]); // Streamdown memoizes/diffs markdown blocks and can hold onto previously