I am developing the chrome ScreenShotShare extension, I need to copy the cropped image to the clipboard. And I found a solution for me.
1. Add "clipboardWrite", "clipboardRead" to the permissions in the manifest.json file
2. do a copy operation in background.html with background.js
3. add to background.html
4. I implement "copyImageToClipboard" to work in background.js
copyImageToClipboard: function () { var img = $('clipboard-img'); img.src = localStorage[this.screenshotURIName]; // I store the image URI in localStorage var div = $('clipboard-div'); div.contentEditable = true; var range; if (document.createRange) { range = document.createRange(); range.selectNodeContents(div); window.getSelection().removeAllRanges(); window.getSelection().addRange(range); div.focus(); document.execCommand('copy'); } div.contentEditable = false; }
code>
Cyanny
source share