Skip to content

Commit bc5e1cf

Browse files
fix: add error handling to shareContent and clipboard operations
1 parent 64e1849 commit bc5e1cf

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

src/lib/viralUtils.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
export function shareContent(title: string, text: string, url?: string) {
1+
export async function shareContent(title: string, text: string, url?: string) {
22
const shareUrl = url || window.location.href;
33
if (navigator.share) {
4-
navigator.share({ title, text, url: shareUrl }).catch(() => {});
4+
try {
5+
await navigator.share({ title, text, url: shareUrl });
6+
} catch {
7+
// User cancelled or share failed, try clipboard fallback
8+
try {
9+
await navigator.clipboard.writeText(`${text} ${shareUrl}`);
10+
} catch {
11+
// Clipboard also failed, silently ignore
12+
}
13+
}
514
} else {
6-
navigator.clipboard.writeText(`${text} ${shareUrl}`).catch(() => {});
15+
try {
16+
await navigator.clipboard.writeText(`${text} ${shareUrl}`);
17+
} catch {
18+
// Clipboard failed, silently ignore
19+
}
720
}
821
}
922

0 commit comments

Comments
 (0)