Giter VIP home page Giter VIP logo

platform.js's Introduction

platform.js's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

platform.js's Issues

OS family/version

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"; }
    }
}

Chrome on iOS gets reported as Safari

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

Detect Breach

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

Documentation of most common values for platform.os.family

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

TypeError: Cannot read property '1' of null at parse call

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.

Errors in FireFox Aurora & FF fork

(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,

Viewport and language

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
    }
    ...
}

Detect Raven version number correctly

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.)

Make Detectable Data Configurable

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` method

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.

Opera (Next) 15.0

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.

Opera Mini 8 for iOS

The new Opera Mini 8 for iOS has 3 different modes:

  • Mini mode, which proxies and renders all sites using Opera’s server;
  • Turbo mode, which just compresses the sites, but renders it using iOS’s WebKit; and
  • Uncompressed mode, which uses iOS’s WebKit, but without any data compression

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?

Chrome Mobile being detected incorrectly

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 Mobile reported as Fennec Mobile

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

Native IE11 detected as null

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] }
*/

Detect nightly WebKit builds

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.

platform.js lib could not pass jshint.

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

Create Booleans

Consider adding booleans to the platform object in order to simplify usage.

For example...

if( platform.os.isAndroid && platform.isChromeMobile ){
    // ...
} else if( platform.isGoogleTV ){
    // ...
}

Refactor "operaClass" code on Line 54

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.

WebStorm

Bower support?

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 :-)

Is mobile platform

It would be great if we could determine is detected platform belongs to mobile e.g. isMobile flag

GoogleTV is detected as Linux armv7l or Linux i686

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 with WebKit layout engine is detected as KHTML

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

iPad version may also be interesting.
There is a way to distinguish between 1, 2 and 3+

Samsung S4 stock browser incorrectly(?) labelled as Chrome Mobile

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?

Playstation Vita is detected as Kindle Fire

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

Detect windows version

It currently does not detect the windows version and incorrectly identifies 32bit windows when I am using 64 bit under 64 bit node.

Browserify: this !== window

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.

Opera Mini and Mobile in desktop mode aren't detected

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 :)

Last tag was many commits and well over a year of development ago.

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.

1.1.0 change in platform.parse(req.headers['user-agent']).os.family ?

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:

1.0.0

var info = platform.parse(req.headers['user-agent']);
console.log(info.family.os);
//-> 'Mac OS X'

1.1.0

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.

FF on Android

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?

Firefox OS

> 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.

Browserify: cannot require 'ringo/engine'

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
  }
}

Chrome for Android is detected as Android Browser

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

Firefox for Android incorrectly identified as "Android Browser"

> 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.