File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -33,11 +33,23 @@ const loadCopyButton = () => {
3333 const makeOnButtonClick = ( ) => {
3434 let timeout = null
3535 // define the behavior of the button when it's clicked
36- return event => {
36+ return async event => {
37+ // check if the clipboard is available
38+ if ( ! navigator . clipboard || ! navigator . clipboard . writeText ) {
39+ return ;
40+ }
41+
3742 clearTimeout ( timeout )
3843 const buttonEl = event . currentTarget
3944 const codeEl = buttonEl . nextElementSibling
40- navigator . clipboard . writeText ( getCopyableText ( codeEl ) )
45+
46+ try {
47+ await navigator . clipboard . writeText ( getCopyableText ( codeEl ) )
48+ } catch ( e ) {
49+ console . error ( e . message )
50+ return
51+ }
52+
4153 buttonEl . innerText = _ ( "Copied!" )
4254 timeout = setTimeout ( ( ) => {
4355 buttonEl . innerText = _ ( "Copy" )
You can’t perform that action at this time.
0 commit comments