File tree Expand file tree Collapse file tree 1 file changed +25
-14
lines changed Expand file tree Collapse file tree 1 file changed +25
-14
lines changed Original file line number Diff line number Diff line change 32
32
return fallBackCopy ( strToCopy ) ;
33
33
}
34
34
35
- navigator . permissions
36
- . query ( { name : "clipboard-write" } )
37
- . then ( ( result ) => {
38
- if ( result . state == "granted" || result . state == "prompt" ) {
39
- navigator . clipboard . writeText ( strToCopy ) . then (
40
- function ( ) {
41
- // ignore and digest
42
- } ,
43
- function ( ) {
44
- return fallBackCopy ( strToCopy ) ;
45
- }
46
- ) ;
47
- } else {
35
+ function _runCopy ( ) {
36
+ navigator . clipboard . writeText ( strToCopy ) . then (
37
+ function ( ) {
38
+ // ignore and digest
39
+ } ,
40
+ function ( ) {
48
41
return fallBackCopy ( strToCopy ) ;
49
42
}
50
- } ) ;
43
+ ) ;
44
+ }
45
+
46
+ // If not chrome, then just run the copy and if it errors
47
+ // let the fallback handle it
48
+ // If chrome, then the permission is checked and if no permissions
49
+ // are enabled then the fallback is run
50
+ if ( ! navigator . userAgent . includes ( "Chrome" ) ) {
51
+ _runCopy ( ) ;
52
+ } else {
53
+ navigator . permissions
54
+ . query ( { name : "clipboard-write" } )
55
+ . then ( ( result ) => {
56
+ if ( result . state == "granted" || result . state == "prompt" ) {
57
+ } else {
58
+ return fallBackCopy ( strToCopy ) ;
59
+ }
60
+ } ) ;
61
+ }
51
62
}
52
63
53
64
function fallBackCopy ( strToCopy ) {
You can’t perform that action at this time.
0 commit comments