get clipboard value and display in an alert in javascript

index.tsx
navigator.clipboard.readText()
  .then(text => {
    alert("Clipboard value: " + text);
  })
  .catch(err => {
    console.error('Failed to read clipboard contents: ', err);
  });
180 chars
8 lines

This code uses the Clipboard API to read the text in the user's clipboard and returns a promise. If the promise resolves successfully, an alert is displayed with the clipboard text. If it fails, an error message will be logged to the console. Note that this is an asynchronous method, so it will not block the execution of other code.

gistlibby LogSnag