The Screenshot plugin allows your application to take custom screenshots of the current screen and save them into the phone. You can also drag the screenshot box and setup a custom size for it using getFrame.
install it via cordova cli
cordova plugin add cordova-custom-screenshot
notice: only jpg format is supported in Android
navigator.screenshot.getFrame({ width: 400, height: 200, x: 50, y: 50 }, (error, res)=> {
if (error) {
console.error(error);
} else {
console.log('File path: ',res.filePath);
}
});
navigator.screenshot.save((error, res) => {
if (error) {
console.error(error);
} else {
console.log('File Path = ',res.filePath);
}
});
take screenshot with jpg and custom quality
navigator.screenshot.save((error, res) => {
if (error) {
console.error(error);
} else {
console.log('File Path = = ',res.filePath);
}
},'jpg',50);
define a filename
navigator.screenshot.save((error, res) => {
if (error) {
console.error(error);
} else {
console.log('File Path = ',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
navigator.screenshot.URI((error, res) => {
if (error) {
console.error(error);
} else {
html = '<img style="width:50%;" src="'+res.URI+'">';
document.body.innerHTML = html;
}
},50);
add this line <preference name="CrosswalkAnimatable" value="true" />
in config.xml, see bug
MIT license