I have a problem with my extension. I want to paste data from the clipboard.
So far, I’ve got this:
function pasteAndGo()
{
document.execCommand('paste')
alert("Pasted")
}
The alert comes up, but nothing has been pasted.
I’ve got a feeling it’s the document part that needs changing, but I don’t know what to do. Any ideas?
There used to be an experimental clipboard API in Chrome, but this was removed in Chrome 13.
Chrome has moved towards the more standard
document.execCommand('paste'),document.execCommand('copy')anddocument.execCommand('cut')commands:In Chrome you’ll need permissions need to be added to your manifest: "clipboardRead" and "clipboardWrite".
Up until Chrome 38, these clipboard permissions were only available to extension pages such as background scripts. As of Chrome 39, content scripts can also use these clipboard APIs after declaring the clipboard permissions in the manifest file.
clipboardRead/clipboardWritepermissions are not respected in content scripts – Chromium Issue (#395376)