javascript - Getting data from Google Chrome Webview to Caller/Parent window -


i'm working on chrome kiosk application (so packaged app limitations apply) that's web browser deployed chrome devices. i'm looking support screenshots, , i'm using html2canvas this, need store them uploaded later on.

i'm calling html2canvas using webview.executescript{file:} callback. in callback i'm executing actual html2canvas call

  webview.executescript({ file: "kiosk/html2canvas.js" }, handlehtml2canvasinjected);    function handlehtml2canvasinjected(event) {      var webview = document.queryselector('webview');      webview.executescript({code: "html2canvas(document.body).then(function(canvas){ //whatever });"});    } 

i can append canvas object body , see screenshot working. however, need returned caller.

i've tried use localstorage, seems webviews storage , caller's storage 2 different things.

it boils down fact need able communicate "stuff" between webview , window created webview.

load webview following lines make sure loaded once execute script it:

webview.addeventlistener("contentload", function () {   webview.executescript({file: "myscript.js"}, function(result) {}); } 

within script can example call html2canvas. can communicate result main script using messaging system:

var body = document.queryselector("body");  html2canvas(body, {     onrendered: function(canvas) {         chrome.runtime.sendmessage({canvas:canvas.todataurl()});     } }); 

then react on onmessage-event in main script:

chrome.runtime.onmessage.addlistener(     function(request, sender, sendresponse) {        if(request.canvas) {           plugin.data.canvas = request.canvas;           // screenshot         }     } ); 

hope helped! :)

[edit]

just found this: https://code.google.com/p/chromium/issues/detail?id=326755

it seems working on native function. called this:

webview.capturevisibleregion({ format: "png" }, function(dataurl) {    var image = new image();   image.src = dataurl;   document.body.appendchild(image); }); 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -