I want to write some text variable into clipboard via Chrome Extension, it will be happened when user presses a short-key. I’ve done all parts except writing to clipboard.
I’ve searched entire StackOverflow using these keywords:
“[google-chrome-extension] Clipboard”
So I want to say, I’ve seen all related to:
- Add
clipboardReadandclipboardWritepermission (already done) - Add text into a
<textarea>, call
document.execCommand('Copy');
or
document.execCommand("Copy", false, null);
Even I tried my extension on StackOverflow’s textarea and I inserted my text into wmd-input part of StackOverflow textarea, then selected it, then called copy. Nothing, nothing, nothing…
Everything tried. Please advise… What am I missing?
You can try the following code, it writes text to clipboard
As an example i wrote
Sampleto clipboardOutput
manifest.json
manifest file is key for all chrome extensions, ensured it is with all permissions
popup.html
A trivial Browser action HTML File, with input box and button
popup.js
It copies content in
<input>to clipboardOR