Skip to content

Instantly share code, notes, and snippets.

@manuhabitela
Created November 13, 2013 20:09
Show Gist options
  • Save manuhabitela/7455526 to your computer and use it in GitHub Desktop.
Save manuhabitela/7455526 to your computer and use it in GitHub Desktop.
basic casperjs conf
var casper = require('casper').create({
verbose: true,
logLevel: "debug",
viewportSize: { width: 1378, height: 768 }, //for real, my screen is like everyone else's!
pageSettings: {
loadImages: false,
loadPlugins: false,
//I'm using Chrome, I SWEAR
userAgent: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36"
},
//don't load any external ressource
onResourceRequested: function(capser, requestData, networkRequest) {
if (requestData.url.indexOf("http://thetarget.com") !== 0) {
networkRequest.abort();
}
}
});
//logging all the thinnnngs
casper.on('page.error', function (msg, trace) { this.echo( 'Error: ' + msg, 'ERROR' ); });
casper.on('remote.message', function(msg) { this.echo('Remote message: ' + msg); });
@n1k0
Copy link

n1k0 commented Nov 13, 2013

You could also subscribe to the resource.requested event and abort from there:

casper.on("resource.requested", function(res, req) {
  if (res.url.indexOf("http://thetarget.com") !== 0) {
    req.abort();
  }
});

@manuhabitela
Copy link
Author

Oh, I missed that in the docs... thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment