This is how far I got:
Added permissions to manifest file:
"permissions": ["clipboardRead", "clipboardWrite"]
I read about chrome.experiment.clipboard, but this appears to have been removed in favour of document.execCommand('copy').
I wrote this program to try it out:
main() {
var copy = new ButtonElement()..text = 'copy';
var paste = new ButtonElement()..text = 'paste';
var textarea = new TextAreaElement()..text = 'foo';
document.body.nodes.addAll([copy, paste, textarea]);
copy.onClick.listen((event) => document.execCommand('copy', null, null));
paste.onClick.listen((event) => document.execCommand('paste', null, null));
}
Ideally, for my application, I'd like to write a function called getClipboardText(), and setClipboardText(String). But first of all I'm trying to just get this basic example to work.
Any ideas on what to try next?
Edit: Updated bug pointed out by amouravski below. Thanks ;)
Fixed - thanks Keith:
class Clipboard {
static String get text {
var active = document.activeElement;
var hidden = new TextAreaElement();
document.body.append(hidden);
hidden.focus();
document.execCommand('paste', null, '');
active.focus();
hidden.remove();
return hidden.value;
}
static set text(String s) {
var active = document.activeElement;
var hidden = new TextAreaElement();
hidden.value = s;
document.body.append(hidden);
hidden.select();
document.execCommand('copy', null, '');
active.focus();
hidden.remove();
}
}