Skip to content

Instantly share code, notes, and snippets.

@wellsie
Forked from iwek/asperjs-useragent-test.js
Last active August 29, 2015 14:10
Show Gist options
  • Save wellsie/956efc8c927f8e01f84b to your computer and use it in GitHub Desktop.
Save wellsie/956efc8c927f8e01f84b to your computer and use it in GitHub Desktop.
var casper = require('casper').create();
var webpage = "http://wordpress.org/";
casper.on('resource.requested', function(resource) {
for (var obj in resource.headers) {
var name = resource.headers[obj].name;
var value = resource.headers[obj].value;
if (name == "User-Agent"){
this.echo(value);
}
}
});
casper.start();
casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X)');
casper.thenOpen('http://google.com/', function() {
this.echo("I'm a Mac.");
});
this.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
this.thenOpen('http://google.com/', function() {
this.echo("I'm a PC.");
});
casper.run();
/*
//OUTPUT: does not work, last user-agent string used for both runs
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
I'm a Mac.
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
I'm a PC.
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment