https://github.com/kartikprabhu Looks like you can also use the Clipboard API (https://caniuse.com/clipboard) to write directly to the clipboard (using navigator.clipboard.writeText) in response to e.g. a click on a link (or button), see and try the code in Example 10 here:
https://w3c.github.io/clipboard-apis/#clipboard-writetext-data