What are Safari User Agents and How to Set One
By Sourojit Das, Community Contributor - August 14, 2024
A user agent refers to a textual representation that is transmitted by web browsers and other client programs to web servers to request a webpage or any other online resource.
When your web browser establishes a connection with a website, it includes a User Agent field in the HTTP header. The user agent field in browsers varies across different browsers, and every browser possesses its unique user agent.
This guide explains in detail what Safari user agents are and how to set one.
- What Are User Agents?
- Types of User Agents
- What is a Safari Browser User Agent?
- Safari on macOS:
- Safari on iPhone (iOS):
What Are User Agents?
A user agent is a mechanism by which a web browser identifies itself to a web server, providing information such as the browser name (e.g., Safari) and the operating system it is running on (e.g., iOS or macOS).
This string contains vital data regarding the client’s device, operating system, browser type, and version. This information allows the server to produce a customized response that meets the client’s requirements.
User agents are crucial in web development and optimization since they ensure that content is shown accurately and optimally across various devices and platforms. Additionally, they facilitate analytics, allowing website proprietors to comprehend the demographics of their site visitors. They can also be employed to manage access or display varying versions of information depending on the user’s capabilities.
Types of User Agents
User agents can be classified into various categories:
- Web browsers use strings to identify themselves to web servers. Popular browsers include Chrome, Firefox, Safari, and Edge.
- Mobile browsers are designed specifically for use on mobile devices, such as those running on iOS and Android operating systems.
- Search engine crawlers, such as Googlebot, Bingbot, and others, are employed by search engines to index online information.
- APIs and Bots: Strings utilized by automated scripts, bots, and API clients to engage with web services.
- Custom User Agents are designed by developers for the purpose of testing or emulating different browsers or devices.
What is a Safari Browser User Agent?
Safari user agents consist of text strings that Safari web browsers transmit to web servers during communication. These strings provide the server with information about the browser, including its version, operating system, and other pertinent facts. Websites and web applications utilize them to provide tailored content and experiences that are optimized according to the browser’s capabilities and requirements.
Some examples of Safari Browser User Agents are demonstrated below –
Safari on macOS:
This Safari user agent for macOS is composed of several key components, each serving a distinct purpose in identifying the browser, operating system, and rendering engine.
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15
The user agent string offers comprehensive data regarding the browser, operating system, and rendering engine in use. Here is a detailed analysis of each component:
- The user agent string “Mozilla/5.0” is being referred to. Traditionally, the initial segment of this string commences with “Mozilla” in order to ensure compatibility. The term “5.0” denotes the specific version of Mozilla, an early web browser.
- (Macintosh; Intel Mac OS X 10_15_7): – This section provides details on the specific operating system and platform being used, which is a Macintosh computer running Intel Mac OS X version 10.15.7. The term “Macintosh” denotes that the gadget is a Mac.
The term “Intel Mac OS X 10_15_7” refers to the macOS version 10.15.7 operating system that is designed to run on a computer with an Intel processor. - The user agent string AppleWebKit/605.1.15 indicates that the browser is using the WebKit rendering engine, which was built by Apple. The version `605.1.15` refers to a particular iteration of the WebKit engine.
- This web browser engine is based on KHTML and is similar to Gecko. This section signifies that WebKit is built upon KHTML, a rendering engine, and is intentionally designed to emulate the behavior of Gecko, the engine utilized by Mozilla Firefox, to ensure compatibility.
- The current version is 14.0.3. This indicates the specific version of the Safari web browser, which is 14.0.3.
- Safari/605.1.15: – This indicates that the browser being used is Safari, precisely version 605.1.15 of Safari, as denoted by the WebKit version number.
The user agent string indicates that the request originates from Safari 14.0.3 on macOS 10.15.7, utilizing the WebKit 605.1.15 rendering engine on an Intel-based Mac.
Read More: Debugging on iOS and Mac Safari
Safari on iPhone (iOS):
This Safari user agent for iOS is composed of several key components, each serving a distinct purpose in identifying the browser, operating system, and rendering engine.
Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1
The user agent string `Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Mobile/15E148 Safari/604.1` provides detailed information about the browser, operating system, and rendering engine being used on an iPhone. Here’s a breakdown of each part:
- Mozilla/5.0: Historically, this part of the string starts with “Mozilla” for compatibility reasons. The “5.0” refers to the version of Mozilla (an early web browser) and is often used generically by modern browsers to indicate compatibility.
- (iPhone; CPU iPhone OS 15_0 like Mac OS X): This section specifies the device and operating system. `iPhone` indicates that the device is an iPhone. `CPU iPhone OS 15_0` specifies that the operating system is iOS version 15.0. `like Mac OS X` indicates that the operating system is similar to macOS in terms of its capabilities and behaviour.
- AppleWebKit/605.1.15: AppleWebKit` indicates that the browser uses the WebKit rendering engine developed by Apple. `605.1.15` is the specific version of the WebKit engine.
- (KHTML, like Gecko): This part indicates that WebKit is based on KHTML, a rendering engine, and is designed to behave like Gecko, the engine used by Mozilla Firefox, for compatibility reasons.
- Version/15.0: This specifies the version of the browser. In this case, it indicates the version of Safari running on iOS 15.0.
- Mobile/15E148: `Mobile` indicates that this is a mobile device. `15E148` is the specific build number of the iOS operating system.
- Safari/604.1: This identifies the browser as Safari, specifically version 604.1 of the Safari browser.
Read More: How to Debug on iPhone Safari for Windows
Together, this user agent string tells web servers that the request is coming from Safari on an iPhone running iOS 15.0, using the WebKit 605.1.15 rendering engine, and is a mobile device with the specific build number 15E148.
How Do You Find Your Current User Agent in Safari?
To ascertain your current browser user agent in Safari, you may employ the subsequent techniques:
Method 1: Utilising Developer Tools on macOS
- Launch Safari: Open the Safari application on your Mac.
- Enable the Develop Menu (if it is not already activated): To access the preferences in Safari, click on the “Safari” option in the menu bar and then select “Preferences”. Select the `Advanced` tab. Select the checkbox labelled “Show Develop menu in the menu bar”.
- Access Developer Tools: – Navigate to the menu bar and select `Develop`. Choose the option “Show Web Inspector” or use the shortcut “Option + Command + I”.
- Inspect User Agent: Navigate to the `Network` section in the Web Inspector. Refresh the webpage. Select the initial request (often the primary document request). Please navigate to the `Headers` tab and locate the `User-Agent` string within the `Request Headers` section.
Method 2: Utilising Internet Resources
- Launch Safari: Open Safari on your Mac or iOS device.
- Access a User Agent Detection Website: Access third-party websites such as WhatIsMyBrowser.com or UserAgentString.com which help in detecting and verifying current browser or user agent string.
Method 3: Utilising JavaScript
- Initiate Safari: Start Safari on your Mac or iOS device.
- Access the Console: On macOS, open the console by going to Develop > Show JavaScript Console or press Option + Command + C.
- Input JavaScript Command: Type navigator.userAgent into the console and press Enter.
- Display User Agent: The console will show the current user agent string.
Employing any of these techniques, you can effortlessly locate and authenticate your current browser user agent in Safari.
How Do I Set a Safari Browser User Agent for a Particular Site?
On macOS, the Develop menu in Safari allows users to set a Safari browser user agent for a particular site.
Here’s how it can be done:
1. Open Safari: Launch Safari on your Mac.
2. Enable the Develop Menu (if not already enabled):
- Go to `Safari` > `Preferences` from the menu bar.
- Click on the `Advanced` tab.
- Check the box that says `Show Develop menu in menu bar`.
3. Set User Agent for a Specific Site:
- Open the website for which you want to set a specific user agent.
- Go to `Develop` in the menu bar.
- Hover over `User Agent` to see a list of predefined user agents.
- Select the user agent you want to use for this site.
For example, you can choose from options like `Safari — iOS 14.1 — iPhone`, `Google Chrome — Windows`, `Mozilla Firefox — Mac`, etc.
4. The selected user agent will apply to the current tab. You can now test the website as if you were using the specified user agent.
The user agent setting will only apply to the current tab and will reset when you open a new tab or restart Safari. If you need to persistently set a user agent for a specific site, consider using browser extensions or developer tools that allow for more advanced configurations.
How to Change the Safari Browser User Agent?
To change the Safari browser user agent on macOS, you can use the Develop menu.
1. Launch Safari on your Mac.
2. Enable the Develop Menu (if not already enabled):
- Go to Safari > Preferences from the menu bar.
- Click on the Advanced tab.
- Check the box that says Show Develop Menu in the menu bar.
3. Change the User Agent:
- In the menu bar, you will now see a Develop menu.
- Click on Develop.
- Hover over User Agent to see a list of predefined user agents.
- Select the user agent you want to use from the list.
4. Options include:
- Default (Automatically Chosen)
- Safari — iOS 14.1 — iPhone
- Safari — iOS 14.1 — iPad
- Google Chrome — Windows
- Mozilla Firefox — Mac
And more.
If you need to enter a custom user agent string, select Other… at the bottom of the User Agent submenu, then enter the desired user agent string in the dialog box and click OK.
If you require a permanent user agent for several sessions and websites, it is advisable to use a browser extension. However, it should be noted that Safari’s available alternatives are more limited than those of other browsers such as Chrome or Firefox. Safari’s built-in features do not explicitly allow for lasting changes to the user agent.
Read More: How to use Devtools for Safari Mobile View?
Why Should You Use Real Devices for Testing Rather than User Agents or Emulators?
Relying on user agent manipulation for testing can lead to inaccurate results because it doesn’t fully replicate the actual environment in which users interact with your application. User agents can mimic different browsers or devices, but they don’t account for real-world factors like hardware differences, network conditions, or actual user behavior.
This approach may miss critical bugs and performance issues that only arise in authentic usage scenarios, potentially leading to false confidence in your application’s reliability and user experience.
Safari emulators replicate the features and capabilities of a genuine Safari browser. However, virtual computers are unable to deliver precise test results as they operate at a slower pace compared to the genuine Safari Browser. Occasionally, teams are unable to replicate certain interactions or achieve precise CSS compatibility.
Consequently, an end-user may encounter an unknown bug that was not identified during testing on emulators.
Read More: Replace mobile browser emulators
BrowserStack offers immediate access to genuine devices equipped with pre-installed versions of Safari, allowing for comprehensive browser testing older browser versions and current versions of Safari. Developers and QA testers can now test across various versions, spanning from Safari 4 to Safari 12.1. Teams also have the ability to automate their tests and connect with CI/CD solutions like CircleCI, TeamCity, and Jenkins by utilising BrowserStack.
Read More: Safari browser testing on real devices
Hence, it is strongly advised to test websites on authentic Safari browsers installed on genuine mobile or desktop devices. By doing this, teams can ensure that they are thoroughly exploring all possibilities to provide the optimal user experience.