views:

144

answers:

2

I'm trying to spoof Opera (under linux) to be an other browser, in this case iPad for some testing purposes. Now I know sites can check which browser is accessing the using for example in PHP $useragent = $_SERVER['HTTP_USER_AGENT']; and in javascript navigator.userAgent (or navigator.platform).

In firefox you can use an addon to easily switch your useragent and other relevant information, but in Opera it seems it bit hard to do.

First in opera.ini you can do:

[User Agent]
Spoof UserAgent ID=1

But this is limited to a predefined list of UserAgents. No room for custom ones.

Also in opera.ini

[ISP]
Id=iPad

This will add iPad to the User Agent of Opera. It's a start and works most of the time on the sites.

In opera.ini you can set a 'User JavaScript file' to load a custom JavaScript file before loading a website:

[User Prefs]
User JavaScript File=/opera_dir/userjs/load.js

In load.js you can do:

navigator.userAgent = "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10"

Because this file gets executed before loading the website I can modify the UserAgent, but this won't work when a site is checking the UserAgent via PHP, but it works for sites checking with Javascript)

So here's my question: is there another way of spoofing a complete custom UserAgent?

A: 

you can also accomplish the same feat using a web-proxy, i'll recommend to try out, Charles Web Debugging Proxy, from the charles proxy introduction

Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. This includes requests, responses and the HTTP headers (which contain the cookies and caching information).

phoenix24
True, but this requires an additional program. Which is unwanted in this case. This is for a browser in a consumer electronics device.
PoweRoy
A: 

You can't. In desktop Opera, that is.

Some custom ("GOGI"-type) developer builds found on http://labs.opera.com might offer the opera:config#UserPrefs|CustomUser-Agent option where you can specify the entire UA string (the builds that were released a while back are rather old by now). Perhaps you'd be better of with the device SDK tools? Have a look at http://dev.opera.com/sdk/

hallvors