🧩 Plasmo Developers�PD
🧩 Plasmo Developers3y ago
69 replies
jonah

Document is not defined on chrome mv3 in a background.ts file

Hello, I have created a context menu that copies something to your clipboard. This is the function I'm using:

function copyToClipboard(text: string) {
  const el = document.createElement("textarea")
  el.value = text
  document.body.appendChild(el)
  el.select()
  document.execCommand("copy")
  document.body.removeChild(el)
}


This works fine with firefox but not on chrome. So, is there a better way to add a string to the users clipboard via a context menu listener event that works with chrome mv3?
Was this page helpful?