Billy S Billy S - 2 months ago 15
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 (https://www.harristeeter.com, 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

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';