/** * Copy text to clipboard with fallback for non-HTTPS contexts * where navigator.clipboard is undefined. */ export async function copyToClipboard(text: string): Promise { if (navigator.clipboard) { return navigator.clipboard.writeText(text) } // Fallback: textarea + execCommand('copy') const ta = document.createElement('textarea') ta.value = text ta.style.position = 'fixed' ta.style.left = '-9999px' document.body.appendChild(ta) ta.select() const ok = document.execCommand('copy') document.body.removeChild(ta) if (!ok) throw new Error('Clipboard copy command failed') }