Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Electron clipboard module


May 25, 2021 Electron


Table of contents


clipboard module provides a way to copy and paste operations . The following example shows how to write a string on a clipboard:

const clipboard = require('electron').clipboard;
clipboard.writeText('Example String');

On the X Window system, there is an optional clipboard. You can control it with selection for each method:

clipboard.writeText('Example String', 'selection');
console.log(clipboard.readText('selection'));

Method

clipboard module has the following methods:

Note: Test APIs have been identified and will be removed in the future .

clipboard.readText([type])

  • type String (optional)

Return content from clipboard in plain text .

clipboard.writeText(text[, type])

  • text String
  • type String (optional)

Add content to the clipboard as plain text .

clipboard.readHtml([type])

  • type String (optional)

Return the tag content in the clipboard.

clipboard.writeHtml(markup[, type])

  • markup String
  • type String (optional)

Add markup content to the clipboard .

clipboard.readImage([type])

  • type String (optional)

Return NativeImage content from the clipboard.

clipboard.writeImage(image[, type])

Write image to the image .

clipboard.readRtf([type])

  • type String (optional)

Return RTF content from the clipboard.

clipboard.writeRtf(text[, type])

  • text String
  • type String (optional)

Write text in RTF format to the text .

clipboard.clear([type])

  • type String (optional)

Empty the clipboard content.

clipboard.availableFormats([type])

  • type String (optional)

Returns an array of formats supported by clipboards .

clipboard.has(data[, type]) Experimental

  • data String
  • type String (optional)

Returns whether the clipboard supports the format of the specified data

console.log(clipboard.has('<p>selection</p>'));

clipboard.read(data[, type]) Experimental

  • data String
  • type String (optional)

Read the data of the data .

clipboard.write(data[, type])

  • data Object
  • type String (optional)
clipboard.write({text: 'test', html: "<b>test</b>"});

Write data to the data .