DEV Community

Discussion on: How to implement copy and paste in a web application

Collapse
 
peerreynders profile image
peerreynders • Edited
setTimeout(() => {
  navigator.clipboard.readText().then((clipText) => console.log(clipText));
}, 5000);
Enter fullscreen mode Exit fullscreen mode

or

setTimeout(async () => {
  const clipText = await navigator.clipboard.readText();
  console.log(clipText);
}, 5000);
Enter fullscreen mode Exit fullscreen mode

Copy either of the snippets into the Chrome DevTools console panel and run it. Then you have 5 seconds to select and copy something before it appears in the console when the timeout expires.

MDN: Clipboard.readText() - Example

Collapse
 
dev_hills profile image
Hillary Chibuko

yea this is awesome content...
The navigator.clipboard.readText returns a promise ....
so listening for a promise and pasting into the console after five seconds is great , because by then the promise most have resolved...
Kudos!!!