Skip to content

Commit 8601dcc

Browse files
authored
fix: not allowed error in safari (#973)
1 parent ab7b668 commit 8601dcc

File tree

1 file changed

+8
-3
lines changed
  • apps/web/src/components/CodemirrorEditor/EditorHeader

1 file changed

+8
-3
lines changed

apps/web/src/components/CodemirrorEditor/EditorHeader/index.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,16 @@ async function copy() {
118118
'text/html': new Blob([temp], { type: `text/html` }),
119119
'text/plain': new Blob([plainText], { type: `text/plain` }),
120120
})
121-
await navigator.clipboard.write([clipboardItem])
121+
// FIX: https://stackoverflow.com/questions/62327358/javascript-clipboard-api-safari-ios-notallowederror-message
122+
// NotAllowedError: the request is not allowed by the user agent or the platform in the current context,
123+
// possibly because the user denied permission.
124+
setTimeout(async () => {
125+
await navigator.clipboard.write([clipboardItem])
126+
}, 0)
122127
}
123128
catch (error) {
124-
console.warn(`Clipboard API 失败,回退到传统方式:`, error)
125-
toast.error(`复制失败,请联系开发者。`)
129+
toast.error(`复制失败,请联系开发者。${error}`)
130+
return
126131
}
127132
}
128133

0 commit comments

Comments
 (0)