Commit 86217d8d 86217d8da1eaeeb7c19277a3b5c34295b9e73d44 by Nicolas Perriault

added an 'onError' Casper setting

1 parent 5b590280
......@@ -222,13 +222,17 @@ phantom.injectJs('path/to/casper.js');
var casper = new phantom.Casper({
clientScripts: [
'includes/jquery.js',
'includes/underscore.js'
'includes/jquery.js', // These two scripts will be injected in remote
'includes/underscore.js' // DOM on every request
],
logLevel: "info",
logLevel: "info", // Only "info" level messages will be logged
onError: function(self, m) { // Any "error" level message will be written
console.log('FATAL:' + m); // on the console output and PhantomJS will
self.exit(); // terminate
},
pageSettings: {
loadImages: false,
loadPlugins: false
loadImages: false, // The WebPage instance used by Casper will
loadPlugins: false // use these settings
}
});
```
......
......@@ -31,6 +31,7 @@
* clientScripts | Array | [] | A collection of script filepaths to include to every page loaded
* logLevel | String | "error" | Logging level (see logLevels for available values)
* onDie | function | null | A function to be called when Casper#die() is called
* onError | function | null | A function to be called when an "error" level event occurs
* onPageInitialized | function | null | A function to be called after WebPage instance has been initialized
* page | WebPage | null | An existing WebPage instance
* pageSettings | Object | {} | PhantomJS's WebPage settings object
......@@ -51,6 +52,7 @@
clientScripts: [],
logLevel: "error",
onDie: null,
onError: null,
onPageInitialized: null,
page: null,
pageSettings: { userAgent: DEFAULT_USER_AGENT },
......@@ -286,6 +288,9 @@
log: function(message, level, space) {
level = level && this.logLevels.indexOf(level) > -1 ? level : "debug";
space = space ? space : "phantom";
if (level === "error" && typeof(this.options.onError) === "function") {
this.options.onError(this, message, space);
}
if (this.logLevels.indexOf(level) < this.logLevels.indexOf(this.options.logLevel)) {
return this; // skip logging
}
......