Chapter 13. Copying and pasting contents from the clipboard

 

This chapter covers

  • Accessing the clipboard in NW.js and Electron
  • Copying text content to the clipboard
  • Clearing the clipboard
  • Copying Electron’s other data types to the clipboard

Copying data from one source and using it in another is a function that’s pretty standard with today’s apps. Some utility apps add value to this functionality by automatically copying screenshots to the clipboard, or keeping track of multiple data items that are copied to the clipboard.

In this chapter, we’ll look at how NW.js and Electron enable you to use the OS’s clipboard to copy and paste content, as well as how to clear the clipboard (a good practice, especially when copying/pasting sensitive data).

By the end of the chapter, you’ll have a good understanding of how to access and alter the user’s clipboard.

13.1. Accessing the clipboard

Copying and pasting from the OS clipboard improves the UX by taking a manual step out of the user journey. Take, for example, the password manager app 1Password by AgileBits. When you enter your password in a website login, the app automatically copies the password to your clipboard for pasting into the password field of the login form the next time you log in.

13.2. Summary