4

I wanna make a extension to copy selection to clipboasd by clicking the ContextMenu. In chrome,many people use a flash solusion.But how can use flash in ContextMenus.It seems impossible.Who can tell me a solusion?

What I did

var a = chrome.contextMenus.create({"title":copy,"context":["selection"],"onclick":copy});
function copy(info,tab){
document.execCommand('selectAll'); //just for example
document.execCommand('copy');
}

I have add clipboardWrite permisson to manifest.json.But it seems doesn't work. "permission":["contextMenus","clipboardWrite"]

user1309417
  • 41
  • 1
  • 3
  • 1
    [This][1] should help. [1]: http://stackoverflow.com/questions/3436102/copy-to-clipboard-in-chrome-extension – chrisjr Apr 03 '12 at 03:09
  • The Experimental Clipboard API has been removed and chrome doesn't support document.execCommand("Copy") and how can I use a flash in ContextMenus. – user1309417 Apr 03 '12 at 03:45
  • May be the experimental API is no longer experimental? http://code.google.com/chrome/extensions/manifest.html#permissions – Alejandro Silvestri Apr 03 '12 at 03:47

2 Answers2

5

Add this permission into your manifest.json:

"permissions": [ "clipboardWrite" ]

And to copy to clipboard:

document.execCommand('copy', false, null);
codef0rmer
  • 10,284
  • 9
  • 53
  • 76
  • I have done that.But it dosn't work ,either.It seems that"document.execCommand('copy')" is also right. – user1309417 Apr 03 '12 at 05:51
  • Then i would suggest to look at the code of Google Url Shortner chrome extension. – codef0rmer Apr 03 '12 at 06:12
  • https://chrome.google.com/webstore/detail/iblijlcdoidgdpfknkckljiocdbnlagk Once you install it in chrome and if you use linux, then goto ~/.config/google-chrome/iblijlcdoidgdpfknkckljiocdbnlagk/ – codef0rmer Apr 03 '12 at 06:19
0

May be this helps. A recent addition to manifest's permissions are clipboardRead and clipboardWrite. Theese let your extension to use the method document.execCommand('copy'), for example.

http://code.google.com/chrome/extensions/manifest.html#permissions

Neysor
  • 3,893
  • 11
  • 34
  • 66
Alejandro Silvestri
  • 3,706
  • 31
  • 43
  • What does it mean by"This permission is required for hosted apps"? – user1309417 Apr 03 '12 at 04:27
  • In Google Chrome extension API documentation, I understand that means that, if you are coding a hosted APP, and need access to clipboard, you will need this permission. Otherwise, it wouldn't be needed, I don't know in which cases. A hosted App is a regular web pages, with an "installable" manifest that allows extra permissions, like an extension, bringing to pages the power of extensions. – Alejandro Silvestri Apr 03 '12 at 10:40