20

Is the user agent for Edge or Spartan browsers known already? Can anyone tell me how to detect this browser and diferentiate it from IE in advance of its release?

Vandervals
  • 5,774
  • 6
  • 48
  • 94
  • 19
    Who cares? It's still a question I want to know the answer to :) Researching... – kieranpotts Jul 20 '15 at 08:30
  • @Cerbrus, I know of this, but in this case I can't avoid doing this. Also, there are thousands of questions regarding detecting ie 9. 10 or 11, and I don't know why this one isn't legitimate – Vandervals Jul 20 '15 at 08:30
  • Spartan and Edge is same. Development project name was spartan. – Mike Phils Jul 20 '15 at 08:32
  • 1
    @Cerbrus And it matters sometimes, particularly with regards to plugin compatibility. E.g., a company is using a plugin that will not provide support for Edge, and Edge doesn't support natively what the plugin does. – Dave Newton Aug 24 '15 at 17:37
  • 9
    Browsers detection is not always bad and its not always possible to feature detect. A classic example is rendering bugs relating to css 3D transforms. If you feature detect, the features are there, but they are broken. So you are left with the option of managing the downgrade of 3D via user agent sniffing until the offending browser is fixed. – CodeToad Jan 12 '16 at 10:33
  • Another use for browser detection: analytics. – Nick Manning Feb 17 '16 at 17:51
  • [This answer](http://stackoverflow.com/a/9851769/1221537) is great for detecting all browsers (including Edge) without user agents – adamdport Jun 24 '16 at 18:22
  • 2
    Possible duplicate of [How to detect Safari, Chrome, IE, Firefox and Opera browser?](http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser) – adamdport Jun 24 '16 at 18:25
  • @Cerbrus Edge is the only browser that doesn't support Bookmarklets - and there's no feature detection for bookmarklets. I also use browser-detection when I want to guide my users to do something on a browser level (click "YES" when the browser asks for location permission, explain how to change cookie settings, etc) – oriadam Jun 27 '16 at 16:48

5 Answers5

18

A simple google search found me the answer you are looking for: http://forum.piwik.org/read.php?3,125732

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0

Therefore you should match: "Edge\/\d+"

Supamiu
  • 8,501
  • 7
  • 42
  • 76
  • so, should I match `"Edge/12.0"` ? – Vandervals Jul 20 '15 at 08:32
  • 2
    You should match "Edge/" followed by a numeric value. The version number will change over time. – kieranpotts Jul 20 '15 at 08:33
  • Just to learn a little about this things... why is this user agent using CHrome and Safari as well? Could that not generate errors in the future while trying to detect those two browsers? – Vandervals Jul 20 '15 at 08:36
  • @Vandervals: There is no standard for user agents, which is part of the reason you really shouldn't use it. – Cerbrus Jul 20 '15 at 08:38
  • 7
    If you detect Edge\/\d+ in the string, you can be sure that the User Agent is a Edge one... – Supamiu Jul 20 '15 at 08:39
  • 2
    @Sapumiu has just provided what I think will be the definitive regex to sniff for Microsoft Edge. No other mainstream browser (currently) includes this string in their user agent. ... In olden non-standards days, webmasters used to block browsers like IE if their website was incompatible with that browser. So browser makers started to put in "Mozilla" into their UA string to try to discourage this practice. In modern standards days, many browsers share the same (or forked) rendering engines, which is why Chrome also reports itself as Safari! It's why web analytics can never be 100% accurate! – kieranpotts Jul 20 '15 at 08:44
  • Doesn't work. Win10 VM from modern.ie "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" – Edi Sep 14 '15 at 16:46
  • 1
    I'm not a fan of UA sniffing. I prefer direct methods: http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser – avgvstvs Jan 04 '16 at 20:58
  • Rather than using regex, `navigator.userAgent.indexOf('Edge') >= 0` worked for me. – adamdport Jun 24 '16 at 18:21
7

According to this answer:

// Internet Explorer 6-11
var isIE = /*@cc_on!@*/false || !!document.documentMode;
// Edge 20+
var isEdge = !isIE && !!window.StyleMedia;
Community
  • 1
  • 1
adamdport
  • 11,687
  • 14
  • 69
  • 91
4

Microsoft Edge UA string:

Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136

I detail why in this blog post.

Neowin recently reported that Microsoft’s new browser for Windows 10, Spartan, uses the Chrome UA string, “Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0″. That is done on purpose.

You’ll also notice that the entire string ends with “Edge/12.0″, which Chrome does not.

I should point out, that this isn’t a redical departure from what Microsoft did with IE 11, which on Windows 8 reads: Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko, as explained in this post.

What is User Agent sniffing?

Often, web developers will UA sniffing for browser detection. Mozilla explains it well on their blog:

Serving different Web pages or services to different browsers is usually a bad idea. The Web is meant to be accessible to everyone, regardless of which browser or device they’re using. There are ways to develop your web site to progressively enhance itself based on the availability of features rather than by targeting specific browsers.

Here’s a great article explaining the history of the User Agent.

Often, lazy developers will just sniff for the UA string and disable content on their website based on which browser they believe the viewer is using. Internet Explorer 8 is a common point of frustration for developers, so they will frequently check if a user is using ANY version of IE, and disable features.

The Edge team details this even deeper on their blog.

All user agents strings contain more information about other browsers than the actual browser you are using – not just tokens, but also ‘meaningful’ version numbers.

Internet Explorer 11’s UA string:

Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko

Microsoft Edge UA string:

Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10136

The userAgent property has been aptly described as “an ever-growing pack of lies” by Patrick H. Lauke in W3C discussions. (“or rather, a balancing act of adding enough legacy keywords that won’t immediately have old UA-sniffing code falling over, while still trying to convey a little bit of actually useful and accurate information.”)

We recommend that web developers avoid UA sniffing as much as possible; modern web platform features are nearly all detectable in easy ways. Over the past year, we’ve seen some UA-sniffing sites that have been updated to detect Microsoft Edge… only to provide it with a legacy IE11 code path. This is not the best approach, as Microsoft Edge matches ‘WebKit’ behaviors, not IE11 behaviors (any Edge-WebKit differences are bugs that we’re interested in fixing).

In our experience Microsoft Edge runs best on the ‘WebKit’ code paths in these sites. Also, with the internet becoming available on a wider variety of devices, please assume unknown browsers are good – please don’t limit your site to working only on a small set of current known browsers. If you do this, your site will almost certainly break in the future.

Conclusion

By presenting the Chrome UA string, we can work around the hacks these developers are using, to present the best experience to users.

Dave Voyles
  • 4,495
  • 7
  • 33
  • 44
3

Another feature-detection based option.

function isBrowserEdge () {
    return typeof CSS !== 'undefined' && CSS.supports("(-ms-ime-align:auto)");
}
Eli Crow
  • 129
  • 2
  • 6
1

Look for "Edge" in the UA string.

While in the minds of the marketing people the world is perfect, in reality browsers have bugs that remain unfixed for years and it will always be the case.

In my case the issue that required me to test for Edge versus Chrome is the Chrome dropdown height bug that Spartan/Edge renders correctly. Microsoft has nothing to fix here and Google has been ignoring that bug for over a year now (it was rendering correctly in old versions of Chrome).