Skip to content

Commit 85c4bf3

Browse files
committed
Add handling of mime_types. Support for different datatypes
1 parent ae65193 commit 85c4bf3

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/api/window_bindings.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,18 +431,43 @@ Window.prototype.reloadDev = function() {
431431
this.reload(3);
432432
}
433433

434-
Window.prototype.capturePage = function(callback, image_format) {
435-
if (image_format != 'jpeg' && image_format != 'png') {
436-
image_format = 'jpeg';
434+
var mime_types = {
435+
'jpeg' : 'image/jpeg',
436+
'png' : 'image/png'
437+
}
438+
439+
Window.prototype.capturePage = function(callback, image_format_options) {
440+
var options;
441+
442+
// Be compatible with the old api capturePage(callback, [format string])
443+
if (typeof image_format_options == 'string' || image_format_options instanceof String) {
444+
options = {
445+
format : image_format_options
446+
};
447+
} else {
448+
options = image_format_options || {};
449+
}
450+
451+
if (options.format != 'jpeg' && options.format != 'png') {
452+
options.format = 'jpeg';
437453
}
438454

439455
if (typeof callback == 'function') {
440456
this.once('__nw_capturepagedone', function(imgdata) {
441-
callback(imgdata);
457+
switch(options.datatype){
458+
case 'buffer' :
459+
callback(new Buffer(imgdata, "base64"));
460+
break;
461+
case 'raw' :
462+
callback(imgdata);
463+
case 'datauri' :
464+
default :
465+
callback('data:' + mime_types[options.format] + ';base64,' + imgdata );
466+
}
442467
});
443468
}
444469

445-
CallObjectMethod(this, 'CapturePage', [image_format]);
470+
CallObjectMethod(this, 'CapturePage', [options.format]);
446471
};
447472

448473
Window.prototype.eval = function(frame, script) {

0 commit comments

Comments
 (0)