Commit 92f5aebf 92f5aebf92d357ed10aa4aa08b497abd595fe700 by Nicolas Perriault

backport fixes of master

1 parent ae57bcf3
......@@ -149,6 +149,7 @@ Casper.prototype = {
*/
capture: function(targetFile, clipRect) {
var previousClipRect;
targetFile = require('fs').absolute(targetFile);
if (clipRect) {
if (!utils.isType(clipRect, "object")) {
throw new Error("clipRect must be an Object instance.");
......@@ -159,10 +160,8 @@ Casper.prototype = {
} else {
this.log('Capturing page to ' + targetFile, "debug");
}
try {
this.page.render(targetFile);
} catch (e) {
this.log('Failed to capture screenshot as ' + targetFile + ': ' + e, "error");
if (!this.page.render(targetFile)) {
this.log('Failed to save screenshot to ' + targetFile + '; please check permissions', "error");
}
if (previousClipRect) {
this.page.clipRect = previousClipRect;
......@@ -888,6 +887,9 @@ Casper.prototype = {
* @return Casper
*/
viewport: function(width, height) {
if (!this.started) {
throw new Error("Casper must be started in order to set viewport at runtime");
}
if (!utils.isType(width, "number") || !utils.isType(height, "number") || width <= 0 || height <= 0) {
throw new Error("Invalid viewport width/height set: " + width + 'x' + height);
}
......
if (!phantom.casperLoaded) {
console.log('This script is intended to work with CasperJS, using its executable.');
phantom.exit(1);
}
var casper = new phantom.Casper({
var casper = require('casper').create({
logLevel: "debug",
verbose: true
verbose: true,
viewportSize: {
width: 1024,
height: 768
}
});
casper.start('https://twitter.com/#!/twilio', function(self) {
......