File tree Expand file tree Collapse file tree 1 file changed +30
-5
lines changed Expand file tree Collapse file tree 1 file changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -431,18 +431,43 @@ Window.prototype.reloadDev = function() {
431
431
this . reload ( 3 ) ;
432
432
}
433
433
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' ;
437
453
}
438
454
439
455
if ( typeof callback == 'function' ) {
440
456
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
+ }
442
467
} ) ;
443
468
}
444
469
445
- CallObjectMethod ( this , 'CapturePage' , [ image_format ] ) ;
470
+ CallObjectMethod ( this , 'CapturePage' , [ options . format ] ) ;
446
471
} ;
447
472
448
473
Window . prototype . eval = function ( frame , script ) {
You can’t perform that action at this time.
0 commit comments