Skip to content

Instantly share code, notes, and snippets.

@mrluanma
Created December 14, 2012 17:16
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mrluanma/4287072 to your computer and use it in GitHub Desktop.
Save mrluanma/4287072 to your computer and use it in GitHub Desktop.
How to set custom UserAgent in CasperJS.
var casper = require('casper').create({
verbose: true,
logLevel: "info",
pageSettings: {
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"
}
});
casper.start("https://httpbin.org/user-agent", function() {
this.test.assertTextExists(
'"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"',
'UserAgent header has been correctly setted.');
});
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment