User agent is a string that helps website owners to identify how the site is being accessed. Using the parameters in user agent string, site owners can configure the server and network for providing necessary access. The web browser like Google Chrome act as a user agent when you open a website. However, it can also be an automated bot that crawls the web like Googlebot. There are many reasons you may want to change user agent in Google Chrome. In this article, we will explain how to change user agent in Google Chrome to spoof the server and get different response.
User Agent String Example
Before proceeding, let us show an example of user agent string when using Chrome with Windows OS. When you open a webpage in Chrome, the browser sends a HTTP request to server for getting the content. In addition, the browser also sends a separate self-identifier request which contains user agent details in the header. There are lot of online tools available to get the user agent details from this HTTP header. In this article, we use this simple tool that shows user agent string, OS, browser name and browser version as shown below.
As you can see, the user agent string shows browser and OS details of the user accessing the webpage.
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
As a site owner, we can configure the web server based on the details available in user agent.
Why to Change User Agent in Chrome?
Here are some of the reasons people try to change the user agent string.
- Developers want to test websites on different browsers, devices and OS versions. It is impossible to physically have all the devices and the easy way is to change user ager and get the corresponding response to test the results.
- Some servers will block users with outdated OS and browser versions. In this case, you can spoof the user agent to view the page without really having the required OS / browser version on your computer.
- Test the responses from server when sending the same request as a user and as a bot.
In most cases, users spoof the user agent string to fake the identity and access blocked content.
How to Change User Agent in Google Chrome?
We will explain two ways to change the user agent string in Chrome. You can use the first method for simple responsive testing while the second method can be used for really spoofing the server.
1. Using Chrome Developer Tools
- Open any webpage in Chrome and right-click on the content area.
- Select “Inspect” option to open Chrome Developer Tools.
- Click on the “Dimensions” dropdown showing on the top tool bar of Developer Tools.
- Select any of the listed device to change the user agent for that device.
- If you do not find your device, click “Edit” showing as a last option.
- Now, you will see a huge list of devices and choose the devices to show in the dropdown list for easy selection.
- For adding your custom user agent string, click on the “Add custom device…” button.
- On the form that appears, fill up the device name, mobile or desktop, user agent string, browser brand, version, platform name and platform version and other details.
- Click “Add” button to add your custom user agent in the list.
Let us say, you select iPhone 12 Pro from the device list, the user agent checker tool will show the following details:
Though this method works to change the user agent in Google Chrome, it is a lengthy way. Also, you need to manually fill up the details for using custom user agents which may be difficult for many users.
2. Using User Agent Changer Extension
Google has an official extension called User-Agent Switcher for Chrome to change the user agent in Chrome. However, we will use User-Agent Switcher and Manager extension in this article. This extension will help to easily change user agent, browser and OS details. You can send the modified user agent in the HTTP request header to server and get the response.
- First, install the extension on your browser from Chrome Web Store.
- After successful installation, open a webpage that you want to spoof and click on the extension icon next to the address bar.
- This will show a huge user agents list for you to select from.
- Let us say, you want to change to Safari on macOS. Select these options from the dropdowns and then select the required user agent from the list. You can apply the changes to either the active window or all windows by clicking on the corresponding buttons.
- Now check your user agent using the tool and you will find it shows Mac Safari as below. You can also click on “Test UA” button in the extension to get the user agent details.
You can use this extension to change to any browser like Firefox, Safari, Edge or Opera with any OS like Android, iOS, Windows, macOS or Linux. Similarly, you can choose the bot option to test Googlebot and other popular automated bots for crawling and viewing the content of webpages. You can also manually edit the user agent name in the text box to send custom value in the string.
Extension Modes
The extension offers three modes to work which you can find by clicking on the extension icon in the address bar. To configure the modes, select “Options” and go to extension’s settings page:
- Black-List Mode – you can enter top-level domain names like google.com to exempt them from using your custom user agent. This means, the domain names you enter in this box will use the default browser’s user agent string and all other domains will use your custom string from the extension.
- White-List Mode – this is the opposite of Black-List Mode. You can enter the domain list to apply the custom user agent string while all other domains will use default string.
- Custom Mode – this is for the advanced users to apply different user agent strings for different domains. Click the “Description” next to “Custom Mode” and click “Insert a sample” link”. This will add a sample custom JSON rule in the box like below with four different rules. First rule defines google.com domain to use Chrome 63 version on macOS. Second rule defines Bing, Yahoo and Wikipedia to use Windows Firefox version 57. Third rule defines the domain example.com to use random user agents in the array. The last rule defines all other domains will use the set user agent from this rule. You can modify these rules to create your own or read the documentation to understand better.
{
"www.google.com": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36",
"www.bing.com, www.yahoo.com, www.wikipedia.org": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0",
"www.example.com": [
"random-useragent-1",
"random-user-agent-2"
],
"*": "useragent-for-all-hostnames"
}
Leave a Reply
Your email is safe with us.