Billy S Billy S - 1 year ago 66
Javascript Question

How do I make websites think PhantomJS is not an iphone?

I just started with PhantomJS a little while ago, though I've been developing javascript for quite a while. However, I noticed something annoying about it; when I go to some sites (, for example), they think I'm using an iphone. I've already tried setting the User Agent to

Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:49.0) Gecko/20100101 Firefox/49.0
, but it dosen't seem to help. Any ideas?

Answer Source

You need to set a useragent AND a desktop-like resolution:

var page = require('webpage').create();
page.viewportSize = { width: 1920, height: 1024 };
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download