Fix clipboard copy with fallback for iOS/older browsers

- Add try-catch around navigator.clipboard.writeText
- Add fallback using textarea + execCommand for older browsers
- Add final fallback using prompt() to show URL if all else fails

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Gemini Agent
2026-01-23 09:19:22 +00:00
parent 1022b1ddca
commit 61e1ac4d81

View File

@@ -91,9 +91,28 @@ export default function SettingsPage() {
}; };
const copyToClipboard = async (text: string) => { const copyToClipboard = async (text: string) => {
await navigator.clipboard.writeText(text); try {
setCopied(true); await navigator.clipboard.writeText(text);
setTimeout(() => setCopied(false), 2000); setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch {
// Fallback for older browsers or permission denied
const textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.position = "fixed";
textArea.style.left = "-9999px";
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand("copy");
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch {
// If all else fails, show the URL in a prompt
window.prompt("Copy this URL:", text);
}
document.body.removeChild(textArea);
}
}; };
const handleImport = async () => { const handleImport = async () => {