A collection of "Best in Class" modules. This means we promote solid browser/environment support, ES5 precedents, unit testing, and plenty of documentation.
John-David Dalton | Benjamin Tan | Kit Cambridge | Mathias Bynens |
A platform detection library.
Home Page: https://mths.be/platform
License: MIT License
A collection of "Best in Class" modules. This means we promote solid browser/environment support, ES5 precedents, unit testing, and plenty of documentation.
John-David Dalton | Benjamin Tan | Kit Cambridge | Mathias Bynens |
Currently, the result only includes one be-all string for OS: "Mac OS X 10.5.8"
etc. I'm looking into replacing our own parser for displaying browser/OS names in the Buster.JS test runner, and for that I need the OS family to generate a class name. Any chance of getting the OS at the same granularity as the platform information? Ideally:
{ /* ... */
os: {
family: "Mac OS X",
version: "10.5.8",
toString: function () { return "Mac OS X 10.5.8"; }
}
}
User agent string for Chrome on iOS6
"Mozilla/5.0 (iPad; CPU OS 6_1_2 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) CriOS/32.0.1700.20 Mobile/10B146 Safari/8536.25"
User agent string for Safari on iOS6
"Mozilla/5.0 (iPad; CPU OS 6_1_2 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B146 Safari/8536.25"
We are using version 1.0.0 of platform.js and chrome on iOS gets reported as safari with version set to 5+.
From Google developers documentation, it seems like the "CriOS/" part of the user-agent string needs to be used to detect chrome. Here is the link - https://developers.google.com/chrome/mobile/docs/user-agent
Thanks,
Naveen
Example UA string for Breach:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Breach Safari/537.36
Thanks for platform.js. Are the most common values for platform.os.family listed in the docs? I was unable to find if it is there, and in that case I'm sorry for opening this issue. If it isn't in the docs, I think this would be a useful addition.
UPDATE 27th May 2014
I'll keep this table updated as new ones are added. Please go to http://jsfiddle.net/bGyNa/4/embedded/result/ to contribute your platform.os.family value if its not yet mentioned in the table:
platform.os.family |
---|
OS X |
Android |
iOS |
Table last updated: 27th May 2014
platform.js version 1.1.0
Hi, there!
I have following error when try to parse user agent:
TypeError: Cannot read property '1' of null
at Object.parse (node_modules/platform/platform.js:783:54)
My user agent is "todotogo/6 (iPhone Simulator; iOS 6.0; Scale/1.00)".
This user agent is auto generated by AFNetworking (https://github.com/AFNetworking/AFNetworking) library.
It would be great if platform.parse method just return null or undefined if he can't parse browser name, version, etc.
(Outdated) FireFox Aurora
"ua": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0"
but
"prerelease": null,`
"manufacturer": null,
FireFox fork PaleMoon
"ua": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:24.0) Gecko/20140316 Firefox/24.0 PaleMoon/24.4.1"
but
"name": null,
"version": null,
"manufacturer": null,
"product": null,
Interested in adding support for viewport and language? If so, I can add it in and submit a pull request.
It would be something similar to the following snippet. It isn't extensively tested but works on latest versions of Chrome and FIrefox (Windows + Linux).
platform = {
...
language: navigator.language || navigator.userLanguage,
viewport: {
width: window.innerWidth,
height: window.innerHeight
}
...
}
UA string looks something like this:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7.1) AppleWebKit/7534.48.3 (KHTML, like Gecko) Version/5.1 Safari/7534.48.3 Raven for Mac/0.5.8635
The 0.5.8635
at the end is the version number. (Currently we use the 5.1
from Version/5.1
.)
Currently the list of detectable data, i.e. browsers, layouts, products, etc. is hard-coded. These values are essentially configuration data against which the code runs. If that configuration could be overridden, developers could target only the data they need, which would improve performance. For example, a developer may only want to run detection against desktop browsers and does not want to waste cycles checking for mobile browsers.
For an AMD environment, it would especially useful if the solution supported the configuration data being external to the code. For example:
define( function(){
// Browsers
return [
'Adobe AIR',
'Arora',
'Avant Browser',
...
];
} )
Add a runInContext
or maybe integrate it as an extension to parse
similar to other bestiejs projects. This would allow gutting the workaround we use in the unit tests.
Example UA string:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.20 Safari/537.36 OPR/15.0.1147.18 (Edition Next)
Platform.js incorrectly reports this as Chrome 28.0.1500.20 on Mac OS X 10.8.4.
It would be convenient to have a minified version for production use.
The new Opera Mini 8 for iOS has 3 different modes:
For Mini mode, the UA is similar to that of other Opera Minis:
"Opera/9.80 (iPhone; Opera Mini/8.0.0/34.2336; U; en) Presto/2.8.119 Version/11.10"
However, for Turbo and Uncompressed modes, the UA is different:
"Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) OPiOS/8.0.0.78129 Mobile/11D201 Safari/9537.53"
@jdalton / @mathiasbynens do you think we should add details to platform.description about whether Opera Mini is in Turbo/Uncompressed modes?
spam
I have quite a few issues with running your library under a node.js server.
For a start, the version here: https://www.npmjs.org/package/platform is very different to the version here: https://github.com/bestiejs/platform.js even though they both say 1.0.0.
Am I doing something wrong here?
Chrome mobile is being incorrectly labelled as Android Browser.
I'm using Mobile Chrome version 27.0.1453.90
The UA string is:
"Mozilla/5.0 (Linux; Android 4.0.4; GT-I9100 Build/IMM76D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.90 Mobile Safari/537.36
Google have put up a link with a pattern for chrome mobile detections so that might be helpful as well
Firefox running on Android 2.3.5 / HTC Sense 3.0 (HTC Desire HD)
platform.description
= "Fennec Mobile 10.0.5 on Android"
platform.ua
= "Mozilla/5.0 (Android; Mobile; rv:10.0.5) Gecko/10.0.5 Firefox/10.0.5 Fennec/10.0.5"
This is a great script, thanks for your efforts.
Cheers,
Dan
var platform = require('platform');
console.dir(platform.parse('Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'));
/**
{ version: null,
name: null,
os:
{ architecture: 32,
family: 'Windows NT',
version: '6.3',
toString: [Function] },
description: 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',
layout: 'Trident',
manufacturer: null,
prerelease: null,
product: null,
ua: 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko',
parse: [Function: parse],
toString: [Function: toStringPlatform] }
*/
Currently they’re recognized as “Safari”, but we could detect it. Easiest and safest solution is to just detect the +
in AppleWebKit/foo+
. If it’s there, it’s a nightly WebKit build.
Hi, I am buidling a web access analytics platform currently. And I found this awesome lib for detecting os and browser, I am happy to use that. But all my source files need to pass grunt task jshint. When it comes to platform.js, few errors occured. Could you check them?
Or could I fixe them make it jshint suitable and deliver a pull request
Consider adding booleans to the platform object in order to simplify usage.
For example...
if( platform.os.isAndroid && platform.isChromeMobile ){
// ...
} else if( platform.isGoogleTV ){
// ...
}
This is totally optional; you obvious had a reason for writing code this way. I personally find it hard to follow: using a variable at the same time as you define it.
var operaClass = reOpera.test(operaClass = getClassOf(opera)) ? operaClass : (opera = null);
WebStorm marks the whole file as erroneous just because of this one error. It is not even an error, since it still works fine. It would be more clear if you break up the code into two separate lines. Use your judgment for this.
@jdalton I've worked on a basic site to showcase platform.js, available at http://d10.github.io/platform-demo/. Do you think we should have a site like Benchmark.js's?
I saw #20 but no support for Bower was added since.
I can probably send a PR, but I encourage anybody to do so before I do :-)
It would be nice to have a possibility to detect Node-Webkit, as well as Adobe ExtendScript. There’s a lack of such lib for these platforms.
http://www.broken-links.com/2012/10/16/internet-explorer-on-xbox-360/
The user agent strings are Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident 5.0; Xbox), and Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; Xbox) for the mobile view.
It would be great if we could determine is detected platform belongs to mobile e.g. isMobile
flag
Version 1:
Mozilla/5.0 (X11; U: Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.127 Large Screen Safari/533.4 GoogleTV/b39389
Version 2:
Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Large Screen Safari/534.24 GoogleTV/192312
Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Large Screen Safari/534.24 GoogleTV/b61925
Version 3:
Mozilla/5.0 (X11; U: Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/17.0.963.56 Large Screen Safari/533.4 GoogleTV/b39389
Konqueror can use the WebKit rendering engine, but it is always detected as KHTML. It is probably a good idea to check if the string AppleWebKit
isn't part of the user agent string.
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/533.3 (KHTML, like Gecko) konqueror/4.8.0 Safari/533.3
Mozilla/5.0 (X11; Linux i686) KHTML/4.8.0 (like Gecko) Konqueror/4.8
iPad version may also be interesting.
There is a way to distinguish between 1, 2 and 3+
Samsung's S4's stock browser is possibly being incorrectly labelled as 'Chrome Mobile', version "1.0".
Heres the platform object as json:
{
"version" : "1.0",
"name" : "Chrome Mobile",
"os" : {
"architecture" : 32,
"family" : "Android",
"version" : "4.2.2"
},
"description" : "Chrome Mobile 1.0 on Samsung (Android 4.2.2)",
"layout" : "WebKit",
"manufacturer" : "Samsung",
"prerelease" : null,
"product" : "Samsung",
"ua" : "Mozilla/5.0 (Linux; Android 4.2.2; en-au; SAMSUNG GT-I9500 Build/JDQ39) AppleWebKit/535.19 (KHTML, like Gecko) Version/1.0 Chrome/18.0.1025.308 Mobie Safari/535.19"
}
Now what i think the issue is that, the new S4 stock browser is actually using a bastardized version of Chrome Mobile, but locked at version 18.0.1025.308. They've also included their own "Version" which in platform's logic makes it think it is Chrome Mobile Version 1 (doesn't exist)
I'm unsure of how to fix this though; Should we label this version of Samsung Galaxy s4 as the 'stock browser' or should we correct the Chrome Mobile version detection logic to label it correctly as Chrome Mobile 18.
Any thoughts/advice?
The pattern (?:Cloud9|Silk)
also matches the useragent string of the Playstation Vita:
Mozilla/5.0 (PlayStation Vita 1.00) AppleWebKit/531.22.8 (KHTML, like Gecko) Silk/3.2
Mozilla/5.0 (PlayStation Vita 1.51) AppleWebKit/531.22.8 (KHTML, like Gecko) Silk/3.2
Mozilla/5.0 (PlayStation Vita 1.52) AppleWebKit/531.22.8 (KHTML, like Gecko) Silk/3.2
Mozilla/5.0 (PlayStation Vita 1.60) AppleWebKit/531.22.8 (KHTML, like Gecko) Silk/3.2
It is better to test for (?:Cloud9|Silk-Accelerated)
instead:
Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Silk/1.0.13.81_10003810) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 Silk-Accelerated=false
Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Silk/1.1.0-84) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 Silk-Accelerated=falseMozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; zh-cn; Silk/1.0.13.81_10003810) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-84) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true
It currently does not detect the windows version and incorrectly identifies 32bit windows when I am using 64 bit under 64 bit node.
When a module is browserified, this
references the exports object, not the window object. This results in the module not being able to determine the browser platform.
self
might be a better variable to use.
Apple renamed Mac OS X to just “OS X” a few years ago. We should do the same.
Opera/9.80 (X11; Linux zbov; U; ar) Presto/2.10.254 Version/12.00
= Opera Mobile, version is correct
Opera/9.80 (X11; Linux zvav; U; en) Presto/2.8.119 Version/10.54
= Opera Mini, ignore version
Try rot13'ing zbov and zvav :)
I was investigating a TypeError originating in this library and bubbling up through helmet
.
TypeError: Cannot read property '1' of null
at Object.parse (my-app/node_modules/helmet/node_modules/platform/platform.js:784:54)
at Object.handle (my-app/node_modules/helmet/lib/middleware/iexss.js:10:32)
at next (my-app/node_modules/express/node_modules/connect/lib/proto.js:193:15)
The issue seems to have been fixed in #16, but no tags have been issued, so there is no tag available for the maintainers of helmet
to use that includes these fixes.
The type of the os.architecture is said to be a string in the docs and code comments though it is actually a number type.
Hey guys -
Happy to provide any proper info you'd like on this, but we noticed that while running ^1.0.0 the following (psuedo) code works as such:
var info = platform.parse(req.headers['user-agent']);
console.log(info.family.os);
//-> 'Mac OS X'
var info = platform.parse(req.headers['user-agent']);
console.log(info.family.os);
//-> 'OS X'
Sadly, we learned this the not fun way by having platform: ^1.0.0
in our package.json
file, so we caught it later on after a build.
Is there any changes to be aware of that would cause this in the version switch? It isn't necessarily not backwards compatible, although our os switch statement broke for the mac user-agents, so we had to update detection there a bit.
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7.1) AppleWebKit/7534.48.3 (KHTML, like Gecko) Version/5.1 Safari/7534.48.3 Raven for Mac/0.5.8635
For all FF version from nightly to release platform.version still returns "Android Browser".
There is a pull request for a fix, isn't it?
Look UA
(Mozilla/5.0 (Windows; U; Windows NT 6.2; en-US; rv:1.8.1.12) Gecko/20080219 Firefox/2.0.0.12 Navigator/9.0.0.6)
> platform.parse("Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0")
{ version: '18.0',
name: 'Firefox Mobile',
os:
{ architecture: null,
family: null,
version: null,
toString: [Function] },
description: 'Firefox Mobile 18.0',
layout: 'Gecko',
manufacturer: null,
prerelease: null,
product: null,
ua: 'Mozilla/5.0 (Mobile; rv:18.0) Gecko/18.0 Firefox/18.0',
parse: [Function: parse],
toString: [Function: toStringPlatform] }
It seems like we could probably identify this as "Firefox OS browser" (or something similar). Firefox Mobile isn't terrible, but might be nice to have a more fine-grained answer.
As browserify cannot determine what will and will not be required at runtime, it requires all the modules and fails attempting to require 'ringo/engine'.
This can be resolved by forcing it not be required in the package.json, but not sure if you want to handle this in another manner.
{
"browser": {
"ringo/engine": false
}
}
I think it should be detected as Chrome, because it does share the same rendering engine with Chrome, and not the stock Android browser.
Mozilla/5.0 (Linux; U; Android 4.0.3; zh-cn; HTC Sensation XE with Beats Audio Build/IML74K) AppleWebKit/535.7 (KHTML, like Gecko) CrMo/16.0.912.77 Mobile Safari/535.7
I'm running Mac OS X Lion on an early 2011 Macbook Pro. platform.architecture
is reporting 32
.
> platform.parse("Mozilla/5.0 (Android; Mobile; rv:23.0) Gecko/23.0 Firefox/23.0")
{ version: '23.0',
name: 'Android Browser',
os:
{ architecture: 32,
family: 'Android',
version: null,
toString: [Function] },
description: 'Android Browser 23.0 (Gecko)',
layout: 'Gecko',
manufacturer: null,
prerelease: null,
product: null,
ua: 'Mozilla/5.0 (Android; Mobile; rv:23.0) Gecko/23.0 Firefox/23.0',
parse: [Function: parse],
toString: [Function: toStringPlatform] }
Will take a stab at a PR + tests, just reporting first.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.