@@ -7,28 +7,19 @@ Behaviour.specify(
77 // HTMLUnit 2.70.0 does not recognize isSecureContext
88 // https://issues.jenkins.io/browse/JENKINS-70895
99 if ( ! window . isRunAsTest && isSecureContext ) {
10- // Make an invisible textarea element containing the text
11- const fakeInput = document . createElement ( "textarea" ) ;
12- fakeInput . value = copyButton . getAttribute ( "text" ) ;
13- fakeInput . style . width = "1px" ;
14- fakeInput . style . height = "1px" ;
15- fakeInput . style . border = "none" ;
16- fakeInput . style . padding = "0px" ;
17- fakeInput . style . position = "absolute" ;
18- fakeInput . style . top = "-99999px" ;
19- fakeInput . style . left = "-99999px" ;
20- fakeInput . setAttribute ( "tabindex" , "-1" ) ;
21- document . body . appendChild ( fakeInput ) ;
22-
23- // Select the text and copy it to the clipboard
24- fakeInput . select ( ) ;
25- navigator . clipboard . writeText ( fakeInput . value ) ;
26-
27- // Remove the textarea element
28- document . body . removeChild ( fakeInput ) ;
29-
30- // Show the completion message
31- hoverNotification ( copyButton . getAttribute ( "message" ) , copyButton ) ;
10+ // Copy the text to the clipboard
11+ navigator . clipboard
12+ . writeText ( copyButton . getAttribute ( "text" ) )
13+ . then ( ( ) => {
14+ // Show the completion message
15+ hoverNotification ( copyButton . getAttribute ( "message" ) , copyButton ) ;
16+ } )
17+ . catch ( ( ) => {
18+ hoverNotification (
19+ "Could not get permission to write to clipboard" ,
20+ copyButton ,
21+ ) ;
22+ } ) ;
3223 } else {
3324 hoverNotification (
3425 "Copy is only supported with a secure (HTTPS) connection" ,
0 commit comments