const copyText = (textToCopy) =>
navigator.clipboard.writeText(textToCopy).then(
() => {
/* clipboard successfully set */
},
() => {
/* clipboard write failed */
}
);
Clipboard.writeText() documentation↗
The user has to interact with the page or a UI element in order for this feature to work (would need to call the
copyText
function in an event listener).The
"clipboard-write"
permission of thePermissions API
is granted automatically to pages when they are in the active tab.