I found out that the default browser of casperjs is safari, because when I tried to access this site using casper and created a screenshot.
How can I change the default browser to chrome?
I found out that the default browser of casperjs is safari, because when I tried to access this site https://z1.expertchoice.com using casper and created a screenshot.
How can I change the default browser to chrome?
Share Improve this question edited Dec 11, 2014 at 1:11 chitcharonko asked Sep 18, 2014 at 2:45 chitcharonkochitcharonko 3312 gold badges6 silver badges18 bronze badges 7 | Show 2 more comments2 Answers
Reset to default 11CasperJS doesn't use Safari. In fact, it can only use PhantomJS and SlimerJS headless browsers for its automation. Therefore, it cannot work with Chrome either.
You are probably hitting a site that does user-agent detection. When a browser makes an HTTP request, it typically includes a request header called User-Agent
which contains information used to identify the browser and other technologies and their versions. For instance:
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
As you have discovered, you can configure your user-agent string in CasperJS using:
casper.userAgent('Your User-Agent String Here');
There are many lists online of well known user-agent strings.
create
parameters
You can also set it on create
:
var casper = require('casper').create({
pageSettings: {
userAgent: 'mystery browser'
}
});
If you pass an empty string, you get: User-Agent: Mozilla/5.0
. Which is likely a sensible prefix to your userAgent
so that PhantomJS will get better output form websites.
You may also be interested in websites which contain common Firefox user agent strings like this one: http://www.useragentstring.com/pages/Firefox/ to make it look like you are a real user.
User-Agent
. For instance, mine right now isMozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36
That tells the server what browser I'm running. – Brad Commented Sep 18, 2014 at 3:38