User agent javascript enabled

Detecting Microsoft Edge from your website

Microsoft Edge enables your website to retrieve user agent information. You use the user agent information to present webpages correctly for each user’s browser. Browsers provide mechanisms for websites to detect browser information such as brand, version number, and host operating system.

  • User-Agent Client Hints are an improved mechanism for retrieving browser information. See User-Agent Client Hints, below.
  • User-Agent strings are legacy; they are outdated and have a history of causing website compatibility problems. See User-Agent strings, below.

You may want to provide different experiences to users based on their browser. For example, if you include steps about how to configure Microsoft Edge or another browser for use with your site, you may want to detect the browser and then show the appropriate content.

Mechanisms for browser detection:

Mechanism Server-side Client-side
User-Agent Client Hints (recommended) Sec-CH-UA HTTPS header navigator.userAgentData JavaScript method
User-Agent string (legacy) User-Agent HTTPS header navigator.userAgent JavaScript method

Feature detection

Microsoft recommends detecting whether a feature is supported in your browser whenever possible, instead of detecting the browser.

If you must detect browsers, Microsoft recommends using User-Agent Client Hints, as follows, together with feature detection.

Читайте также:  Untitled 1

User-Agent Client Hints

Microsoft Edge supports User-Agent Client Hints starting with version 90.

User-Agent Client Hints is a method that addresses privacy concerns while allowing web pages to detect browser information such as browser name, version number, platform, and more. Soon the User-Agent string will be frozen and deprecated by various browsers. For example, the Chrome Platform Status site describes the change in Feature: Reduce User Agent string information.

Employ User-Agent Client Hints when you want to:

  • Determine if new browser activity is from the expected user.
  • Customize hints or instructions if the user is new to this site.

Don’t use User-Agent Client Hints to:

User-Agent Client Hints HTTPS header

When Microsoft Edge sends an HTTPS request to a server, it sends a set of low entropy User-Agent Client Hints headers. For more information, see Low entropy hint table. If the server requires more granular information about the browser, its response includes an Accept-CH header. The value of that response header is a comma-separated list of all the Client Hints request headers the server wants from the browser, such as Accept-CH: Sec-CH-UA-Full-Version,Sec-CH-UA-Platform-Version . The next Microsoft Edge HTTPS request to the server will include the specified User-Agent Client Hints headers.

By default, Microsoft Edge sends the Sec-CH-UA , Sec-CH-UA-Mobile , and Sec-CH-UA-Platform request headers in the following format.

Sec-CH-UA: "Chromium";v="92", "Microsoft Edge";v="92", "Placeholder;Browser Brand";v="99" Sec-CH-UA-Mobile: ?0 Sec-CH-UA-Platform: "Windows" 

The following table shows all available hints request headers with sample values.

User-Agent request header Example User-Agent response value
Sec-CH-UA «Chromium»;v=»91″, «Microsoft Edge»;v=»91″, «GREASE»;v=»99″
Sec-CH-UA-Mobile ?0
Sec-CH-UA-Full-Version 91.0.866.0
Sec-CH-UA-Platform Windows
Sec-CH-UA-Platform-Version 10.0
Sec-CH-UA-Arch x86
Sec-CH-UA-Bitness 64
Sec-CH-UA-Model Surface Pro

User-Agent Client Hints are only sent over secure connections using HTTPS .

User-Agent Client Hints JavaScript API

You can access User-Agent Client Hints using JavaScript on the client side. When you call the default navigator.userAgentData , it returns the following response.

Microsoft Edge includes a GREASE brand value that changes over time. It prevents sites from matching the entire brand list when attempting to detect a version of Microsoft Edge.

To send a request for more detailed information such as platform , use the following code:

navigator.userAgentData.getHighEntropyValues( ["architecture", "model", "platform", "platformVersion", "uaFullVersion"]) .then(ua => < console.log(ua) >); 

The response has the following format:

platformVersion Hint

The operating system version token in the User-Agent header hasn’t been updated for Windows 11, and still reports Windows NT 10.0 .

To distinguish between Windows 10 and Windows 11, request the platformVersion client hint in Microsoft Edge. Values between and including 1.0.0 and 12.0.0 represent releases of Windows 10, while values of 14.0.0 or later represent releases of Windows 11.

Combine User-Agent Client Hints with feature detection

Combining User-Agent Client Hints with feature detection is an effective way to deliver compatible web content. Microsoft recommends using this pattern to:

  • Improve code maintainability.
  • Reduce code fragility.
  • Reduce code breakage from changes to the User-Agent string.

If you need to check for a Chrome-like browser, Microsoft recommends detecting Chromium , which is the engine that powers Microsoft Edge.

Use this method to verify the Chromium brand and apply detection to all affected Chromium-based browsers:

function isChromium() < for (brand_version_pair of navigator.userAgentData.brands) < if (brand_version_pair.brand == "Chromium")< return true; >> return false; > 

Use the above method to avoid hard-coding checks for brands at specific indices. Display orders of brand names can change over time.

If you can’t use feature detection, don’t use a hardcoded list of known Chromium-based browsers for verification. Examples of hardcoded browser names include Microsoft Edge and Google Chrome . Feature detection may not be available, because a fix for a Chromium bug in later versions must be avoided and the affected browsers are difficult to detect.

User-Agent strings

User-Agent strings are outdated and have a long history of causing website compatibility issues.

Wherever possible, Microsoft recommends minimizing use of Microsoft Edge browser detection logic based on the User-Agent string. If you have a good reason to detect the browser, the Microsoft Edge team recommends using User-Agent Client Hints as the primary detection logic. User-Agent Client Hints also reduces the complexity of browser detection code.

For legacy reference, the following information was included in User-Agent string.

On Windows, the User-Agent HTTP request header includes:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36 Edg/90.0.818.46 

On Android, the User-Agent HTTP request header includes:

Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Mobile Safari/537.36 EdgA/90.0.818.46 

The response value from navigator.userAgent method uses the following format:

"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4501.0 Safari/537.36 Edg/91.0.866.0" 

Platform identifiers change based on the operating system, and version numbers increment over time. The format is the same as the Chromium user agent with the addition of a new Edg token at the end. Microsoft chose the Edg token to avoid compatibility issues caused by Edge string, which was previously used for the legacy Microsoft Edge browser based on EdgeHTML. The Edg token is also consistent with existing tokens used for iOS and Android.

Microsoft Edge version increment change

Microsoft Edge’s major version number will soon be incrementing from two digits, such as Edg/99 , to three digits as in Edg/100 . Site owners should make sure their User-Agent parsing logic is robust and works as expected.

Identifiers for Microsoft Edge on various platforms

On desktop operating systems, Microsoft Edge is commonly identified by the Edg token in the User-Agent string. However, a different token for Microsoft Edge is used on some device platforms, as follows:

Platform Identifier token
Desktop (Windows/Mac/Linux) Edg
iPhone/iPad EdgiOS
Android (Mobile/tablet) EdgA

Microsoft Edge Legacy is no longer supported. See the Microsoft Edge Legacy section for details.

Map the User-Agent string to an expanded browser name

Map the User-Agent string tokens to human-readable browser names to use in code. This practice is common across the web. When you map the new Edg token to a browser name, Microsoft recommends using a different name than the one used for the legacy Microsoft EdgeHTML browser, to avoid accidentally applying legacy workarounds that don’t apply to Chromium-based browsers.

User-Agent overrides

Sometimes, a website doesn’t recognize the Microsoft Edge user agent. As a result, a set of the features of the website may not work correctly. When Microsoft is notified about the types of issues, Microsoft contacts you (a website owner) and informs you about the updated user agent.

You may need more time to update and test the user agent detection logic for your website to address the issues reported by Microsoft. To maximize compatibility for your users, the Microsoft Edge Beta and Stable channels use a list of user agent overrides. Use the user agent overrides while you update your website. The list of user agent overrides is provided by Microsoft.

The overrides specify new user agent values that Microsoft Edge sends instead of the default user agent for specific websites. To display the list of user agent overrides that are currently applied:

The Microsoft Edge Canary and Dev channels don’t currently receive user agent overrides. The Microsoft Edge Canary and Dev channels provide environments that use the default Microsoft Edge user agent. Use the Microsoft Edge Canary and Dev channels to reproduce issues on your website caused by the default Microsoft Edge user agent.

To turn off user agent overrides in the Microsoft Edge Beta or Stable channels:

  1. Open a command prompt. For example, enter cmd in the Windows search text box and select the Command Prompt app.
  2. Copy the following code:
--disable-domain-action-user-agent-override 
 --disable-domain-action-user-agent-override 

Microsoft Edge Legacy

Legacy browser considerations:

  • The Microsoft Edge Legacy browser is no longer supported. See the blog post New Microsoft Edge to replace Microsoft Edge Legacy.
  • Microsoft Edge Legacy was only available on Windows 10.
  • Of all the User-Agent mechanisms described in this article, the only supported browser-specific mechanism for Microsoft Edge Legacy is User-Agent string.
  • The User-Agent string for Microsoft Edge Legacy includes the Edge token. A fully formed example of a Microsoft Edge Legacy User-Agent string: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19582

Источник

Оцените статью