diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts index 8e571ddc63..5762baeaf5 100644 --- a/frontend/src/lib/utils.ts +++ b/frontend/src/lib/utils.ts @@ -341,12 +341,30 @@ export async function copyToClipboard(value?: string, sendToast = true): Promise } let success = false - if (navigator?.clipboard) { + if (navigator?.clipboard && window.isSecureContext) { success = await navigator.clipboard .writeText(value) .then(() => true) .catch(() => false) + } else { + const textArea = document.createElement("textarea"); + textArea.value = value; + textArea.style.position = "fixed"; + textArea.style.left = "-999999px"; + + document.body.appendChild(textArea); + textArea.select(); + + try { + document.execCommand('copy'); + success = true; + } catch (error) { + // ignore (success = false) + } finally { + textArea.remove(); + } } + sendToast && sendUserToast(success ? 'Copied to clipboard!' : "Couldn't copy to clipboard", !success) return success