Fever
Fever

Reputation: 317

Electron clipboard.writeHTML is not a function

I wanted to access the clipboard using the Electron clipboard module. I wrote:

const clipboard = require("electron")
// add an eventlister on my button to copy the innerHTML of div "content" 
document.getElementById("copy").addEventListener("click", () => {
         const code = document.getElementById('content').innerHTML
         // the line below complains: "Uncaught TypeError: clipboard.writeHTML is  not a function"
         clipboard.writeHTML(code)
         
     })

I was wondering why and couldn't figure it out for a whole day. Any suggestion would be appreciated. Thank you!

Upvotes: 0

Views: 253

Answers (1)

BrunoLM
BrunoLM

Reputation: 100381

Clipboard is not the default export from electron. You need:

const { clipboard } = require('electron')

See https://www.electronjs.org/docs/latest/api/clipboard

And MDN on export

Upvotes: 1

Related Questions