File tree 1 file changed +14
-2
lines changed
1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -33,11 +33,23 @@ const loadCopyButton = () => {
33
33
const makeOnButtonClick = ( ) => {
34
34
let timeout = null
35
35
// 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
+
37
42
clearTimeout ( timeout )
38
43
const buttonEl = event . currentTarget
39
44
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
+
41
53
buttonEl . innerText = _ ( "Copied!" )
42
54
timeout = setTimeout ( ( ) => {
43
55
buttonEl . innerText = _ ( "Copy" )
You can’t perform that action at this time.
0 commit comments