Skip to content

Commit 3e8aa50

Browse files
authored
fix(front): fix clipboard copy on chrome (#1497)
1 parent f25eaf3 commit 3e8aa50

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/lib/utils/share.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ export async function share(url: string, title: string, appendLeafId: boolean =
1717
if (navigator.share && !isDesktop(window)) {
1818
navigator.share({ url, title });
1919
} else {
20-
if (document.hasFocus()) {
21-
await navigator.clipboard.writeText(url);
22-
} else {
23-
alert("Document is not focused. Please try again.");
24-
}
20+
// this is really ugly
21+
// but on chrome the clipboard write doesn't work if the window isn't focused
22+
// and after we use confirm() to ask the user if they want to share, the window is no longer focused
23+
// for a few ms until the confirm dialog closes. tried await tick(), tried window.focus(), didnt work
24+
// bug doesnt occur in firefox, if you can find a better fix for it please do
25+
await new Promise((resolve) => setTimeout(resolve, 250));
26+
await navigator.clipboard.writeText(url);
2527
}
2628
}

0 commit comments

Comments
 (0)