Clipboard

Accessing the clipboard through JavaScript can be very useful if you're trying to quickly copy or paste something from/into a field. The clipboard functionality allows writing to and reading from the clipboard.

The clipboard functionality is blocked if the browser deems the connection insecure, so someone malicious cannot simply read out your clipboard, especially when you're trying to copy the password or something, or paste something malicious into your clipboard that could cause harm when you finally paste it out again.

It works like so:

$("#changelog-copy").click(() => {
    let text = $("#out-changelog").val()
 
    navigator.clipboard.writeText(text).then(
        () => {
            alert("Copied successfully")
        },
        () => {
            alert("Failed to copy")
        },
    );
})

You get a click event on a button for example, this could be anything though.

You then get the value of the thing you wanna copy, in this case the content of the changelog output.

You can then use

navigator.clipboard.writeText(text)

To write it to the clipboard