diff --git a/src/components/SocialShare.tsx b/src/components/SocialShare.tsx index 7f3cf60..c332c23 100644 --- a/src/components/SocialShare.tsx +++ b/src/components/SocialShare.tsx @@ -55,15 +55,47 @@ const SocialShare: React.FC = ({ } try { + // Check if clipboard API is available + if (!navigator.clipboard) { + // Fallback for older browsers or insecure contexts + const textArea = document.createElement('textarea'); + textArea.value = text; + textArea.style.position = 'fixed'; + textArea.style.left = '-999999px'; + textArea.style.top = '-999999px'; + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + + try { + document.execCommand('copy'); + toast({ + title: "Copied!", + description: "Link copied to clipboard", + }); + } catch (err) { + console.error('Fallback copy failed:', err); + toast({ + title: "Error", + description: "Failed to copy to clipboard", + variant: "destructive", + }); + } finally { + document.body.removeChild(textArea); + } + return; + } + await navigator.clipboard.writeText(text); toast({ title: "Copied!", description: "Link copied to clipboard", }); } catch (err) { + console.error('Copy failed:', err); toast({ title: "Error", - description: "Failed to copy to clipboard", + description: "Failed to copy to clipboard. Please copy the URL manually.", variant: "destructive", }); }