Skip to content

Commit 28e39b9

Browse files
refactor: add trycatch
1 parent a89338c commit 28e39b9

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

app/composables/useClipboardAsync.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@ export function useClipboardAsync(
1818
immediate: false,
1919
})
2020

21-
function copy() {
21+
async function copy() {
2222
const asyncClipboard = new ClipboardItem({
2323
'text/plain': fn().then(text => {
2424
return new Blob([text], { type: 'text/plain' })
2525
}),
2626
})
2727

28-
copied.value = true
29-
navigator.clipboard.write([asyncClipboard])
30-
timeout.start()
28+
try {
29+
await navigator.clipboard.write([asyncClipboard])
30+
copied.value = true
31+
timeout.start()
32+
} catch {
33+
copied.value = false
34+
}
3135
}
3236

3337
return {

0 commit comments

Comments
 (0)