Skip to content
Nate
Stephens

Write Text to the Clipboard

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 the Permissions API is granted automatically to pages when they are in the active tab.


Last Updated: