# Changing the User-Agent Header

The **User-Agent** HTTP Header lets servers identify the application, operating system, vendor, and/or version of the client that sends the request. Usually, each application sends its own specific `User-Agent` string value, but in some cases developers might want to quickly test server responses based on multiple different user agents.

When Fiddler issues a request through its **Composer** it automatically set its own `User-Agent` value. You might observe a similar behavior when using other third-party proxy tools chained to Fiddler.

You can easily create a rule that changes the `User-Agent` for any HTTP request that goes through Fiddler while using the Fiddler rules.

The following examples show how to create a few different rules named "Change User-Agent" that effectively mock the Chrome browser on Windows and macOS.

## Creating a "Set User-Agent" Rule for a Chrome Browser on Windows

Create a "Set User-Agent Chrome Windows" rule by setting the following actions through the [Rules Builder](https://www.telerik.com/fiddler/fiddler-everywhere/documentation/modify-and-filter-traffic/modify-traffic-with-rules).

1. Create an action that sets the HTTP Request header **user-agent** to the following value:
   ```bash
   Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36`.
   ```
2. Create an action that sets the HTTP Request header **sec-ch-ua-platform** to **"Windows"**.
3. Create an **Update Response Body** action that sets the following regular expression match:
   ```javascript
   (<script(?:(?!src).)*?>)
   ```
   and update as:
   ```javascript
   $1!function e(t,r){if(navigator.__defineGetter__?navigator.__defineGetter__("userAgent",function(){return r}):Object.defineProperty&&Object.defineProperty(navigator,"userAgent",{get:function(){return r}}),t.navigator.userAgent!==r){var n={get:function(){return r}};try{Object.defineProperty(t.navigator,"userAgent",n)}catch(i){t.navigator=Object.create(navigator,{userAgent:n})}}}(window,"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36");
   ```

This sample Fiddler rule matches all sessions and explicitly changes the user agent.

![Creating "Set User-Agent Chrome Windows" rule](https://www.telerik.com/fiddler/fiddler-everywhere/documentation/assets/5d1ce4922c3e3dc3905a54a6b58ad693/adv-change-ua-chrome-windows.png)

Once the rule is created, enable the **Rules** tab, toggle the rule switch, and start capturing traffic.

![Activating the "Set User-Agent Chrome Windows" rule](https://www.telerik.com/fiddler/fiddler-everywhere/documentation/assets/e266cfc9f0629b2d4735e90fb0dcbe71/adv-change-ua-chrome-windows-active.png)

Download a ready-to-use <a href="https://github.com/telerik/fiddler-everywhere/tree/master/rules/changing-user-agent-chrome-windows" target="_blank">"Set User-Agent Chrome Windows"</a> rule as a FARX file, which you can import through the Rules toolbar.

## Creating a "Set User-Agent" Rule for a Chrome Browser on macOS

Create a "Set User-Agent Chrome Mac" rule by setting the following actions through the [Rules Builder](https://www.telerik.com/fiddler/fiddler-everywhere/documentation/modify-and-filter-traffic/modify-traffic-with-rules).

1. Create an action that sets the HTTP Request header **user-agent** to the following value:
   ```bash
   Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
   ```
2. Create an action that sets the HTTP Request header **sec-ch-ua-platform** to **"Mac"**.
3. Create an **Update Response Body** action that sets the following regular expression match:
   ```javascript
   (<script(?:(?!src).)*?>)
   ```
   and update as:
   ```javascript
   $1!function e(t,r){if(navigator.__defineGetter__?navigator.__defineGetter__("userAgent",function(){return r}):Object.defineProperty&&Object.defineProperty(navigator,"userAgent",{get:function(){return r}}),t.navigator.userAgent!==r){var n={get:function(){return r}};try{Object.defineProperty(t.navigator,"userAgent",n)}catch(i){t.navigator=Object.create(navigator,{userAgent:n})}}}(window,"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36");
   ```

This sample Fiddler rule matches all sessions and explicitly changes the user agent to mock a Chrome browser on macOS.

![Creating "Set User-Agent Chrome Mac" rule](https://www.telerik.com/fiddler/fiddler-everywhere/documentation/assets/bcdee3d87e78e4b10792810d20163ab2/adv-change-ua-chrome-mac.png)

Once the rule is created, enable the **Rules** tab, toggle the rule switch, and start capturing traffic.

![Activating the "Set User-Agent Chrome Mac" rule](https://www.telerik.com/fiddler/fiddler-everywhere/documentation/assets/e266cfc9f0629b2d4735e90fb0dcbe71/adv-change-ua-chrome-mac-active.png)

Download a ready-to-use <a href="https://github.com/telerik/fiddler-everywhere/tree/master/rules/changing-user-agent-chrome-macos" target="_blank">"Set User-Agent Chrome Mac"</a> rule as a FARX file, which you can import through the Rules toolbar.

## See Also

* [Learn more about the Rules functionality in Fiddler Everywhere here...](https://www.telerik.com/fiddler/fiddler-everywhere/documentation/modify-and-filter-traffic/modify-traffic-with-rules)
* [Learn more about all rules presets in Fiddler Everywhere here...](https://www.telerik.com/fiddler/fiddler-everywhere/documentation/rules-presets)
* [Learn more on how to organize your rules here...](https://www.telerik.com/fiddler/fiddler-everywhere/documentation/modify-and-filter-traffic/organizing-rules)
* [Learn more about the matching conditions here...](https://www.telerik.com/fiddler/fiddler-everywhere/documentation/modify-and-filter-traffic/conditions-and-actions#conditions)
* [Learn more about the supported actions here...](https://www.telerik.com/fiddler/fiddler-everywhere/documentation/modify-and-filter-traffic/conditions-and-actions#actions)
* [Learn more about final and non-final rules here...](https://www.telerik.com/fiddler/fiddler-everywhere/documentation/modify-and-filter-traffic/conditions-and-actions#final-and-non-final-actions)
* [Learn more about using breakpoints here...](https://www.telerik.com/fiddler/fiddler-everywhere/documentation/modify-and-filter-traffic/breakpoints)
