Created
December 17, 2020 15:10
-
-
Save wesleybliss/8cf5400db8626297583da230e194fae5 to your computer and use it in GitHub Desktop.
Copy to clipboard #js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const copyToClipboard = async (text) => { | |
if (!navigator.clipboard) | |
// Clipboard API not available | |
throw new Error('Your browser doesn\'t allow clipboard access') | |
try { | |
await navigator.clipboard.writeText(text) | |
} catch (e) { | |
log.error('Failed to copy', e) | |
throw new Error('Could not copy to your clipboard') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment