Skip to content

Instantly share code, notes, and snippets.

@billyct
Created September 16, 2015 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billyct/bedb985628cc7f9763e9 to your computer and use it in GitHub Desktop.
Save billyct/bedb985628cc7f9763e9 to your computer and use it in GitHub Desktop.
casper js add cookies,extend phatom.addCookie()
casper.__addCookies = function (cookies) {
if (Array.isArray(cookies)) {
cookies.forEach(function(cookie) {
if (typeof cookie === 'object') {
phantom.addCookie(cookie);
} else {
this.log('its a object like {name: xxxx, value: xxxx...}?', 'warning');
}
});
} else {
this.log('not an array of cookies', 'warning');
}
}
casper.addCookies = function(arg) {
if (typeof arg === 'string') {
var jsons = require(arg);
this.__addCookies(jsons);
} else {
this.__addCookies(arg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment