To read to the user’s clipboard, you use the readText method:
const clipboardData = await navigator.clipboard.readText();
To write to the user’s clipboard, you use the writeText method:
The API is obviously very easy to use — each method returns a Promise so you can use async/await or then callbacks. The difficult part is striking the balance of when to use each. Unnecessary reads will feel invasive, and unnecessary writes will significantly dissolve user trust.
When may you want to write to the clipboard? Possibly after the user pastes a seed phrase, password, or credit card number into likewise named form fields.
Sure you can use the numerous libraries available to simulate this API, but know that an official API does exist. And as always, I’m teaching you how to use it — it’s up to you to ensure it’s the right time and tool for the job!