开发者

Spoofing UserAgent in Opera

开发者 https://www.devze.com 2022-12-31 15:48 出处:网络
I\'m trying to spoof Opera (under Linux) to be another browser, in this case iPad for some testing purposes.

I'm trying to spoof Opera (under Linux) to be another browser, in this case iPad for some testing purposes. Now I know sites can check which browser is accessing it 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 user agent 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 开发者_JAVA百科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.

Is there another way of spoofing a complete custom UserAgent?


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/


You can 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消