Spaces:
Runtime error
Runtime error
fix(front): fix clipboard copy on chrome (#1497)
Browse files- src/lib/utils/share.ts +7 -5
src/lib/utils/share.ts
CHANGED
|
@@ -17,10 +17,12 @@ export async function share(url: string, title: string, appendLeafId: boolean =
|
|
| 17 |
if (navigator.share && !isDesktop(window)) {
|
| 18 |
navigator.share({ url, title });
|
| 19 |
} else {
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
| 25 |
}
|
| 26 |
}
|
|
|
|
| 17 |
if (navigator.share && !isDesktop(window)) {
|
| 18 |
navigator.share({ url, title });
|
| 19 |
} else {
|
| 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);
|
| 27 |
}
|
| 28 |
}
|