Need help with cordova-screenshot?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

gitawego
205 Stars 147 Forks Other 116 Commits 69 Opened issues

Description

screenshot plugin for cordova/phonegap

Services available

!
?

Need anything else?

Contributors list

cordova-screenshot

NPM version

The Screenshot plugin allows your application to take screenshots of the current screen and save them into the phone.

how to install

install it via cordova cli

cordova plugin add https://github.com/gitawego/cordova-screenshot.git

notice: in iOS, only jpg format is supported in Android, the default WebView and Crosswalk are both supported

usage

navigator.screenshot.save(function(error,res){
  if(error){
    console.error(error);
  }else{
    console.log('ok',res.filePath);
  }
});

take screenshot with jpg and custom quality

js
navigator.screenshot.save(function(error,res){
  if(error){
    console.error(error);
  }else{
    console.log('ok',res.filePath);
  }
},'jpg',50);

define a filename

js
navigator.screenshot.save(function(error,res){
  if(error){
    console.error(error);
  }else{
    console.log('ok',res.filePath); //should be path/to/myScreenshot.jpg
  }
},'jpg',50,'myScreenShot');

screenshot files are stored in /sdcard/Pictures for android.

take screenshot and get it as Data URI

js
navigator.screenshot.URI(function(error,res){
  if(error){
    console.error(error);
  }else{
    html = '';
    document.body.innerHTML = html;
  }
},50);

usage in AngularJS

.service('$cordovaScreenshot', ['$q', function ($q){
    return {
        capture: function (filename, extension, quality){
            extension = extension || 'jpg';
            quality = quality || '100';

        var defer = $q.defer();

        navigator.screenshot.save(function (error, res){
            if (error) {
                console.error(error);
                defer.reject(error);
            } else {
                console.log('screenshot saved in: ', res.filePath);
                defer.resolve(res.filePath);
            }
        }, extension, quality, filename);

        return defer.promise;
    }
};

}])

Known Issue

in Android platform I receive the black image with crosswalk

solution:

add this line

 in config.xml, see bug

License

this repo uses the MIT license

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.