Skip to content

Commit

Permalink
fix(front): fix clipboard copy on chrome (#1497)
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarrazin authored Sep 27, 2024
1 parent f25eaf3 commit 3e8aa50
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/lib/utils/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ export async function share(url: string, title: string, appendLeafId: boolean =
if (navigator.share && !isDesktop(window)) {
navigator.share({ url, title });
} else {
if (document.hasFocus()) {
await navigator.clipboard.writeText(url);
} else {
alert("Document is not focused. Please try again.");
}
// this is really ugly
// but on chrome the clipboard write doesn't work if the window isn't focused
// and after we use confirm() to ask the user if they want to share, the window is no longer focused
// for a few ms until the confirm dialog closes. tried await tick(), tried window.focus(), didnt work
// bug doesnt occur in firefox, if you can find a better fix for it please do
await new Promise((resolve) => setTimeout(resolve, 250));
await navigator.clipboard.writeText(url);
}
}

0 comments on commit 3e8aa50

Please sign in to comment.