Change the Browser User Agent in Chrome, Safari, & Firefox
A web browsers user agent is how a website knows what type of computer, operating system, and browsing app you are using. Some sites serve different themes, CSS, content, or even different sites to different browsers and OS’s, and many developers often need to change their own user agent to be able to test these abilities and build these alternate sites.
We’ll cover how to change the user agent for all popular modern web browsers available to the desktop user in Mac OS X and Windows, including Chrome, Safari, and Firefox.
How to Change the User Agent in Chrome
All new versions of Chrome include the ability to change user agent very easily, and it’s more powerful with more options than the simplified options available to Safari users. With Chrome’s user agent overrides, the user agents device resolution can also be specified, forcibly redrawing the page within that resolution. There is no need to enable the user agent settings in Chrome, you just have to find them under the developer options:
- Open Chrome and pull down the “View” menu, go down to “Developer” and select “Developer Tools” to open the developer panel
- Click the gear icon Settings button located in the lower right corner
- Click the ‘Overrides” tab to find the User Agent options, select a user agent out of the pulldown menu, modify an existing one, or enter a new user agent
Chrome also instantly redraws pages with the new user agent, and if device metrics are set it will also use that devices set resolution size when redrawing the page.
How to Change the Browser User Agent in Safari
By far the easiest way to change a user agent on the Mac is through Safari’s Develop menu, if that hasn’t been enabled yet we’ll cover that and also show how to change user agents easily:
- Open Safari, then pull down “Preferences” from the Safari menu
- Click on “Advanced” tab and check the box next to “Show Develop menu in menu bar”
- Close out of Preferences and find the new “Develop” menu alongside “Window”, pull that down and select “User Agent”
- Pick any pre-specified user agent or select “Other” to use a different user agent string
Note that if you hover over a specific user agent, the exact UA string used will appear in a yellow box alongside the menu item.
After selecting any of the user agents, you will find the currently open web page will refresh. If the page in question happens to serve different information to alternate browsers you may find the page looks different. For example, changing a user agent to a mobile device and mobile browser may cause some web pages to send you to their mobile websites, or serve a different looking page through a responsive layout.
How to Change Browser User Agent in Firefox Without Using an Extension
Firefox can also do this by default, though it’s arguably the most clumsy of the modern browsers and thus not really recommended since some Firefox extensions handle it better.
- Enter about:config into the URL box and hit return
- Search for “useragent” (one word) and create a new string titled “general.useragent.override”
- Place the user agent in and choose “OK”
Keep in mind that changing the user agent does not change the way the web browser renders pages itself, unless it is being served user-agent specific content. For example, using an IE8 user agent is not the same as visiting a page with IE8 and letting it render the page, a need often mandatory for web developers. For that you will need to actually take the time to run Internet Explorer in a virtual machine on top of Mac OS X, that is free and fairly easy to set up.
What about spoofing user agents from the command line?
For the command line junkies, you can also use curl for this purpose and retrieve a pages source code as a different browser or OS, the basic syntax is:
curl -A "UserAgentString" http://url.com
The videos below demonstrate enabling the ability and changing the browser user agent in Safari under OS X, and also how to do this in Chrome under Mac OS X, Windows, or Linux:
Keep in mind that changing the user agent does not change the way the web browser renders pages itself, unless it is being served user-agent specific content. For example, using an IE8 user agent is not the same as visiting a page with IE8 and letting it render the page, a need often mandatory for web developers. For that you will need to actually take the time to run Internet Explorer in a virtual machine on top of Mac OS X, that is free and fairly easy to set up if necessary.
Thanks to @ImpechCerrato for the tip idea, you can follow @OSXDaily on Twitter too.