Javascript: Uncaught Error: Too many listeners for downloads.onDeterminingFilename -
here's code:
assets.foreach(function(v) { var canvas = document.createelement('canvas'); canvas.id = "canvas"; canvas.width = 200; canvas.height = 150; var ctx = canvas.getcontext("2d"); var img = new image(); img.src = 'file:///path/to/file/' + v.name; img.onload = function () { ctx.drawimage(img, 0, 0, img.width, img.height-256, 0, 0, 200, 150); }; document.getelementbyid('download').addeventlistener('click', function() { chrome.downloads.download({ url: canvas.todataurl() }); chrome.downloads.ondeterminingfilename.addlistener( function(downloaditem, cb) { console.log(downloaditem); cb({ filename: 'path/to/file/thumb-' + v.name.split('_')[0] + '.png', conflictaction: 'overwrite' }); return true; } ); }, false ); });
this works if there's 1 file in folder. if more, work single file only. how can figure out work many files?
please note, saves new thumbnail same folder initial image is.
you cannot have more 1 ondeterminingfilename
listener:
ondeterminingfilename
during filename determination process, extensions given opportunity override target downloaditem.filename. each extension may not register more 1 listener event.
Comments
Post a Comment