0

I'm writing extension for Google Chrome. I'm trying to read\write data from clipboard using this method:

chrome.tabs.executeScript( {
     code: "document.addEventListener('copy', function(e){ var data=e.clipboardData.getData('text'); alert(data);});"   
  })

But, it didn't work. If I correctly understood this documentation, above method should work. So, what could be the problem?

Teyam
  • 7,686
  • 3
  • 15
  • 22
bronstein87
  • 115
  • 1
  • 9
  • 2
    Possible duplicate of [How to get Clipboard data in Chrome Extension?](http://stackoverflow.com/questions/22702446/how-to-get-clipboard-data-in-chrome-extension) – Aᴄʜᴇʀᴏɴғᴀɪʟ Sep 25 '16 at 13:34
  • Cᴀʟʟᴏᴅᴀᴄɪᴛʏ, i'm interested exactly in clipboardData.getData method – bronstein87 Sep 25 '16 at 15:02
  • 2
    `event.clipboardData.getData()` returns a zero length string from `copy` and `cut` events. It does return valid data from `paste` events. – Makyen Sep 25 '16 at 19:15
  • I think Makyen is on to something. See [the spec](https://www.w3.org/TR/clipboard-apis/#dfn-allowed-to-read-from-clipboard) on when you can read the clipboard. Do you have the `"clipboardRead"` permission? Even then, it may only work within the extension context and not the content script. – Xan Sep 26 '16 at 10:08

0 Answers0