javascript - Copy image to clipboard from Chrome App (not Extension or Page) -


i struggling copy image clipboard chrome app. please keep in mind asking in relation new chrome apps (formerly known chrome packaged apps) not chrome extension or regular web page in chrome.

i have requested "clipboardwrite" , "clipboardread" permissions in manifest.json

"permissions": [     {"filesystem": ["write", "retainentries", "directory"]},      "https://www.google-analytics.com/",     "storage",     "clipboardwrite",     "clipboardread" ], 

based on related "copy image clipboard" questions here on stackoverflow, have tried 4 different approaches.

function onclickbutton() {     document.oncopy = function(event) {         var dataurl = "data:image/png;base64,ivborw0kggoaaaansuheugaaaaqaaaadcaiaaaa7ljmraaaageleqvqiw2p4dwcmdaxafbvmaheqmygcacehg8elxtbpaaaaaelftksuqmcc";         // base64 decode data url, skipping data url prefix          var data = atob(dataurl.substring("data:image/png;base64,".length));         // copy decoded data binary array          var dataarray = new uint8array(data.length);         (var = 0; < data.length; i++) {             dataarray[i] = data.charcodeat(i);         }          // approach 1 - failed, pastes nothing         event.clipboarddata.setdata('image/png', dataarray);          // approach 2 - failed, pastes nothing         event.clipboarddata.setdata('text/uri-list', dataurl);          // approach 3 - failed, ends pasting text "image.png"         var file = new file(dataarray, "image.png", {type: "image/png"});         event.clipboarddata.items.add(file);          // approach 4 - failed, pastes nothing         event.clipboarddata.items.add(dataurl, 'text/uri-list');          event.preventdefault();     };     document.execcommand("copy"); } 

this code run 1 of 4 approaches uncommented. there approach works?? fyi, approach 1 works fine "text/plain" , sample text. reasonably sure @ least approach working apis something.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -