Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
102 views
in Technique[技术] by (71.8m points)

javascript - What is the list of possible values for navigator.platform as of today?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Disclaimer: please note this property is sent by the browser and can thus be faked, just like user agent strings. Never rely on the navigator object to be completely accurate.

The definition

As far as I know there isn't a single public list of all possible `navigator.platform` values, even though the property has been around for quite a bit. To make things worse, the property's definition changed throughout the years. It used to be:

navigator.platform indicates the machine type for which the browser was compiled.

This basically means the property can return Win16 when the user is running a browser compiled for 16-bit, even though the user is on a 32-bit or 64-bit Windows machine.

Of course W3Schools lists the old definition (I'm not even gonna link to them). W3 and MDN have agreed on a different definition though:

navigator.platform represents the platform on which the browser is executing.

Still, this definition is a bit vague. A decade ago a 'platform' would either be a CPU architecture or an operating system. In recent years handheld and media devices can be platforms too.


The interpretation

As with everything on the web, our fate is in the hands of the mighty browser vendors. In this case, all the major browsers (IE, Safari, Firefox and Chrome) agree that my 64-bit Windows machine is a `Win32` platform. This means they're sticking to the old definition as far as Windows goes, because none of them are compiled for 64-bit thus far. Look on the bright side though: at least they all agree on something for once.

It seems like we're a bit luckier when it comes to handheld and media devices. As you've already stated in your question, the iPhone, iPod and iPad each got a unique value, even though they're all running the same operating system. All of Nintendo's and Sony's devices are returning unique values too. So only now navigator.platform is starting to look interesting.

But then Opera Mini for iPhone comes along, messing things up again. Opera Mini actually returns a code engine version number, which is a completely different interpretation of platform than anything we've come across so far. So now we're back where we started and we start to understand why there's so little information on this subject out there.

Even though the interpretations vary and I don't have a complete answer for you, I did feel like I should add my 2 cents for anyone else out there researching the navigator.platform property.


The list

Below is a (definitely non-definite) list of the values I know of that I could verify with multiple sources. Because of the vague definition, I'm not too sure what the best way to order these is. For now I divided them into a few categories based on operating system or device brand and listed additional information and release dates where applicable.

Android

It's really hard to test for Android devices. Android devices will return Android just as often as some version of Linux. For example on a Nexus 5 phone, both the Android browser and Chrome return Linux armv7l. In rare cases Android devices can even return null (instead of undefined).

  • Android (2008)
  • Linux: see notes above
  • null

Apple

As far as iOS goes: Safari, Chrome and Mercury agree, but Opera messes things up.

  • iPhone (2007)
  • iPod (2007)
  • iPad (2010)
  • iPhone Simulator: simulator shipped with Xcode
  • iPod Simulator: simulator shipped with Xcode
  • iPad Simulator: simulator shipped with Xcode
  • Macintosh
  • MacIntel: Intel processor (2005)
  • MacPPC: PowerPC processor
  • Mac68K: 68000 processor
  • Pike v7.6 release 92: Opera Mini 5 on any iPhone (2009)
  • Pike v7.8 release 517: Opera Mini 7 on any iPhone (2012)

BlackBerry

  • BlackBerry (2003)

FreeBSD

  • FreeBSD
  • FreeBSD i386: x86 (IA-32) processor
  • FreeBSD amd64: AMD x86-64 processor

Linux

Seriously unreliable because so many platforms are built on this. For example, Chrome on ChromeOS or Linux x86-64 both return Linux i686 as that's what they were compiled for.

Note Linux ARM lists architecture flags, e.g. armv5tej would denote a v5 ARM architecture with Thumb support ('T'), a DSP instruction set ('E'), and Jazelle support ('J').

  • Linux
  • Linux aarch64
  • Linux armv5tejl
  • Linux armv6l
  • Linux armv7l
  • Linux armv8l
  • Linux i686
  • Linux i686 on x86_64
  • Linux i686 X11: based on X11 Window System
  • Linux MSM8960_v3.2.1.1_N_R069_Rev:18: Sony Xperia V
  • Linux ppc64
  • Linux x86_64
  • Linux x86_64 X11: based on X11 Window System

Microsoft

Even on a 64-bit Windows 8 they all stick to Win32.

  • OS/2 (1994?)
  • Pocket PC
  • Windows
  • Win16: Windows 3.1x (1992?)
  • Win32: Windows 95 and up
  • WinCE

Mozilla (Firefox OS)

An empty string is returned in the web browser on Firefox OS. See this bug report.

KaiOS

The web browser on KaiOS (based on Firefox) also returns the empty string (same as Firefox OS). See this bug report.

Nintendo

  • New Nintendo 3DS (2014)
  • Nintendo DSi (2008)
  • Nintendo 3DS (2011)
  • Nintendo Wii (2006)
  • Nintendo WiiU (2012)

OpenBSD

  • OpenBSD amd64

Symbian / S40

  • Nokia_Series_40 (1999?)
  • S60 (2002?)
  • Symbian: Opera on Symbian
  • Symbian OS

Palm

  • PalmOS (1996)
  • webOS (2009)

Solaris

  • SunOS
  • SunOS i86pc
  • SunOS sun4u: SPARC processor

Sony

  • PLAYSTATION 3 (2006)
  • PlayStation 4 (2013)
  • PSP: PlayStation Portable (2004)

Various

  • HP-UX: Hewlett-Packard UniX
  • masking-agent: value changes to this when using Masking Agent for Firefox
  • WebTV OS
  • X11: X11 Window System

Have a device that's not on this list? Please leave a comment listing your device's properties and its navigator.platform value (feel free to use this JSFiddle to find the value).

Hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...