279

All popular browsers' user agent strings, even Internet Explorer's, start with Mozilla/. Why is this the case?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
sashaeve
  • 9,387
  • 10
  • 48
  • 61
  • 5
    User agents have been used to tell web servers “**I’m not a random crap; I _also_ support features that these support.** Please do not discriminate against me.” Hence the user agent of a browser having all others in it. – Константин Ван Aug 20 '19 at 15:44

6 Answers6

361

It is a long and sad story.

In summary:

  1. Mozilla browser gets released, with User-Agent Mozilla/1.0 (Win3.1). It is publicly renamed to Netscape, but in its User-Agent it keeps its original name .
  2. Internet Explorer is released. It spoofs Netscape by starting its User-Agent with Mozilla/ because web servers were routinely browser sniffing and serving pages with frames - a feature supported by both Netscape and IE, but not other browsers of the era - to Netscape only.
  3. Over time, Gecko, Konqueror, Opera, Safari and Chrome each decide to similarly spoof the User-Agent of some previous browser in order to manipulate browser-sniffing web pages into correctly understanding their browser's features. As part of this spoofing, all the browsers start their User-Agents with Mozilla/, like the browsers before them had done. Plenty of other nonsense also results, like modern Chrome's User-Agent simultaneously claiming to be Mozilla, Chrome, Safari, and 'like Gecko'.
Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Jason C
  • 21,377
  • 10
  • 38
  • 33
  • 1
    Like the link, but also check out Mike Mu's wikipedia link for more info. – Curtis Tasker Jul 11 '09 at 18:22
  • 33
    Note that the "Mozilla" here is **not** the current open-source project of that name, but the original codename of Netscape, thought to refer to "Mosaic Killer". The codename was reused many years later for the open source project, whose rendering engine is the "Gecko" mentioned here. – IMSoP Feb 05 '14 at 20:12
  • 93
    And here we are in 2015, still perpetuating the stupidity. MS Edge's user agent string is `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.1`. – filoxo Aug 04 '15 at 17:24
  • 29
    No wonder it's hard to do browser detection, they're all pretending to be one another! – Sarsaparilla Nov 14 '18 at 19:09
  • 10
    The browser wars weren't without casualties. – Pikamander2 May 07 '19 at 06:54
  • 24
    If `userAgent` String is such a mess, then, why is it not deprecated and/or removed? – Melvin Abraham Jun 03 '19 at 17:42
  • 5
    @MelvinAbraham It is still useful because not all requests come from browsers. You may need to look at browser vs. server (API) traffic for example – Dagrooms Sep 09 '19 at 19:14
  • 3
    Bonus point for the linked article, quite hilarious. "And there was much rejoicing" – marcovtwout Jun 10 '20 at 14:28
  • 1
    What does "frame" mean? Is it `iframe`? – Minh Nghĩa Aug 30 '21 at 13:28
  • 2
    Nope, "frame" refers to Frameset. A now-deprecated way of making UIs with HTML and duct tape. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/frameset – Vineel Shah Sep 29 '21 at 21:46
32

I think it had to do with: http://en.wikipedia.org/wiki/User_agent#User_agent_spoofing

Back in the early days, Netscape (code named Mozilla) was the main rival of IE, and they wanted to prevent being rejected by sites rejecting browsers other than Netscape.

Mike Mu
  • 977
  • 6
  • 10
16

As mentioned by @Jason "Its a long story". Summing that story up "its just every browser pretends to be Mozilla"

After trying everything, I have finally used: http://www.useragentstring.com/

You can use the above website to get the formatted user agent and OS.
They have an API which you can use directly...

user5664615
  • 400
  • 1
  • 10
  • 17
Abhishek Goel
  • 18,785
  • 11
  • 87
  • 65
  • 3
    Pedantic correction: every browser, including Mozilla, pretends to be Netscape, whose user-agent began Mozilla. The fact that the codename was reused just adds to the confusion. – IMSoP Feb 05 '14 at 20:14
  • 2
    Mozilla and Firefox codebase was originally part of Netscape though. That's why many of Firefox internal APIs has "ns" as its prefix. – Lie Ryan Dec 10 '14 at 00:09
8

Reason for this are the infamous browser wars.

In short - browsers started to pretend to be some other browser, because some websites served content based on which browser asked for it and they also wanted content meant for other browsers.

I find it surprising it still haven't been solved to this day. Since userAgent can't be safely removed for legacy reasons, why some new feature clearly identifying a browser wasn't introduced? Yes, most of the time you don't need browser detection, but rather a feature detection, but it is not built-in JS neither!

lot
  • 1,434
  • 18
  • 23
3

Because that's how Netscape identified itself, and Microsoft wanted to work with sites that would detect Netscape and reject anything else.

billpg
  • 3,195
  • 3
  • 30
  • 57
2

Mozilla/5.0 is the general token that says the browser is Mozilla compatible, and is common to almost every browser today. for more detail click here

Pankaj Chauhan
  • 1,623
  • 14
  • 12
  • 3
    This is a little misleading - note that the "Mozilla" being referred to is actually the Mozilla (Mosaic-killer) browser, which was rebranded to Netscape before release (and which most readers have probably never heard of by its original name) - *not* Mozilla the non-profit free software community that's still around today. – Mark Amery Aug 29 '17 at 11:06