To copy text to the clipboard using the Clipboard API, you can call the navigator.clipboard.writeText() method and pass in the text that you want to copy as an argument. This method returns a promise that resolves when the text has been successfully copied to the clipboard, or rejects if there was an error.
When using the Clipboard API, it's important to note that the user must grant permission for your website to access their clipboard. This permission is granted when the user performs a clipboard-related action, such as pasting text into an input field.
Source code viewer