Skip to content

Commit ea9ca5c

Browse files
fix: add try-catch to clipboard and share in BollywoodDialog
1 parent 1edb6dc commit ea9ca5c

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/pages/play/BollywoodDialog.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,26 @@ export default function BollywoodDialog() {
5454
setHistory(prev => [item, ...prev].slice(0, 10));
5555
};
5656

57-
const copyDialog = useCallback(() => {
57+
const copyDialog = useCallback(async () => {
5858
if (!current) return;
59-
navigator.clipboard.writeText(`"${current.dialog}" — ${current.movie} (${current.actor})\n\nGet more at snapforest.in 🔥`);
59+
try {
60+
await navigator.clipboard.writeText(`"${current.dialog}" — ${current.movie} (${current.actor})\n\nGet more at snapforest.in 🔥`);
61+
} catch {
62+
// Clipboard failed (non-secure context), silently ignore
63+
}
6064
}, [current]);
6165

6266
const shareDialog = useCallback(async () => {
6367
if (!current) return;
6468
const text = `"${current.dialog}" — ${current.movie} (${current.actor})\n\nGet more Bollywood dialogs at snapforest.in 🔥`;
65-
if (navigator.share) { try { await navigator.share({ title: 'Bollywood Dialog', text }); } catch {} }
66-
else { await navigator.clipboard.writeText(text); alert('Copied!'); }
69+
if (navigator.share) {
70+
try { await navigator.share({ title: 'Bollywood Dialog', text }); } catch {
71+
// Share cancelled or failed, try clipboard
72+
try { await navigator.clipboard.writeText(text); } catch { /* ignore */ }
73+
}
74+
} else {
75+
try { await navigator.clipboard.writeText(text); } catch { /* ignore */ }
76+
}
6777
}, [current]);
6878

6979
return (

0 commit comments

Comments
 (0)