Important Notes:
- This API requires a secure context (HTTPS).
- Users must interact with the page (e.g., click a button) before clipboard access is allowed for security reasons.
const toClipboard = async (text) => {
try {
await navigator.clipboard.writeText(text);
}
catch (error) {
console.log(error)
}
}
const fromClipboard = async () => {
try {
return navigator.clipboard.readText();
}
catch (error) {
console.log(error)
}
}