Safari 兼容
Clipboard API
Javascript Clipboard API write() does not work in Safari | Stack Overflow
在 Safari 中,Clipboard API 无法在 await 之后立即调用。
bash
报错:`NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.`报错:`NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.`解决方案:
通过
setTimeout绕过 Safari 的限制
ts
const link = await getLink()
setTimeout(() => {
copy(link).then(() => {
console.log('copied')
})
}, 0)const link = await getLink()
setTimeout(() => {
copy(link).then(() => {
console.log('copied')
})
}, 0)