Giter VIP home page Giter VIP logo

useragent's Introduction

useragent - high performance user agent parser for Node.js

Useragent originated as port of browserscope.org's user agent parser project also known as ua-parser. Useragent allows you to parse user agent strings with high performance and accuracy by using hand tuned regular expressions for browser matching. This database is needed to ensure that every browser is correctly parsed as every browser vendor implements it's own user agent schema. This is why regular user agent parsers have major issues because they will most likely parse out the wrong browser name or confuse the render engine version with the actual version of the browser.


Build status BuildStatus


High performance

The module has been developed with a benchmark driven approach. It has a pre-compiled library that contains all the Regular Expressions and uses deferred or on demand parsing for Operating System and device information. All this engineering effort has been worth it as this benchmark shows:

Starting the benchmark, parsing 62 useragent strings per run

Executed benchmark against node module: "useragent"
Count (61), Cycles (5), Elapsed (5.559), Hz (1141.3739447904327)

Executed benchmark against node module: "useragent_parser"
Count (29), Cycles (3), Elapsed (5.448), Hz (545.6817291171243)

Executed benchmark against node module: "useragent-parser"
Count (16), Cycles (4), Elapsed (5.48), Hz (304.5373431830105)

Executed benchmark against node module: "ua-parser"
Count (54), Cycles (3), Elapsed (5.512), Hz (1018.7561434659247)

Module: "useragent" is the user agent fastest parser.

Hand tuned regular expressions

This module relies on uap-core's regexes.yaml user agent database to parse user agent strings.

This database is up-to-date thanks to contributors such as you. Feel free to submit issues and pull requests.


Installation

Installation is done using the Node Package Manager (NPM). If you don't have NPM installed on your system you can download it from npmjs.org

npm install useragent --save

The --save flag tells NPM to automatically add it to your package.json file.


API

Include the useragent parser in you node.js application:

var useragent = require('useragent');

The useragent library allows you do use the automatically installed RegExp library or you can fetch it live from the remote servers. So if you are paranoid and always want your RegExp library to be up to date to match with agent the widest range of useragent strings you can do:

var useragent = require('useragent');
useragent(true);

This will async load the database from the server and compile it to a proper JavaScript supported format. If it fails to compile or load it from the remote location it will just fall back silently to the shipped version. If you want to use this feature you need to add yamlparser and request to your package.json

npm install yamlparser --save
npm install request --save

useragent.parse(useragent string[, js useragent]);

This is the actual user agent parser, this is where all the magic is happening. The function accepts 2 arguments, both should be a string. The first argument should the user agent string that is known on the server from the req.headers.useragent header. The other argument is optional and should be the user agent string that you see in the browser, this can be send from the browser using a xhr request or something like this. This allows you detect if the user is browsing the web using the Chrome Frame extension.

The parser returns a Agent instance, this allows you to output user agent information in different predefined formats. See the Agent section for more information.

var agent = useragent.parse(req.headers['user-agent']);

// example for parsing both the useragent header and a optional js useragent
var agent2 = useragent.parse(req.headers['user-agent'], req.query.jsuseragent);

The parse method returns a Agent instance which contains all details about the user agent. See the Agent section of the API documentation for the available methods.

useragent.lookup(useragent string[, js useragent]);

This provides the same functionality as above, but it caches the user agent string and it's parsed result in memory to provide faster lookups in the future. This can be handy if you expect to parse a lot of user agent strings.

It uses the same arguments as the useragent.parse method and returns exactly the same result, but it's just cached.

var agent = useragent.lookup(req.headers['user-agent']);

And this is a serious performance improvement as shown in this benchmark:

Executed benchmark against method: "useragent.parse"
Count (49), Cycles (3), Elapsed (5.534), Hz (947.6844321931629)

Executed benchmark against method: "useragent.lookup"
Count (11758), Cycles (3), Elapsed (5.395), Hz (229352.03831239208)

useragent.fromJSON(obj);

Transforms the JSON representation of a Agent instance back in to a working Agent instance

var agent = useragent.parse(req.headers['user-agent'])
  , another = useragent.fromJSON(JSON.stringify(agent));

console.log(agent == another);

useragent.is(useragent string).browsername;

This api provides you with a quick and dirty browser lookup. The underlying code is usually found on client side scripts so it's not the same quality as our useragent.parse method but it might be needed for legacy reasons.

useragent.is returns a object with potential matched browser names

useragent.is(req.headers['user-agent']).firefox // true
useragent.is(req.headers['user-agent']).safari // false
var ua = useragent.is(req.headers['user-agent'])

// the object
{
  version: '3'
  webkit: false
  opera: false
  ie: false
  chrome: false
  safari: false
  mobile_safari: false
  firefox: true
  mozilla: true
  android: false
}

Agents, OperatingSystem and Device instances

Most of the methods mentioned above return a Agent instance. The Agent exposes the parsed out information from the user agent strings. This allows us to extend the agent with more methods that do not necessarily need to be in the core agent instance, allowing us to expose a plugin interface for third party developers and at the same time create a uniform interface for all versioning.

The Agent has the following property

  • family The browser family, or browser name, it defaults to Other.
  • major The major version number of the family, it defaults to 0.
  • minor The minor version number of the family, it defaults to 0.
  • patch The patch version number of the family, it defaults to 0.

In addition to the properties mentioned above, it also has 2 special properties, which are:

  • os OperatingSystem instance
  • device Device instance

When you access those 2 properties the agent will do on demand parsing of the Operating System or/and Device information.

The OperatingSystem has the same properties as the Agent, for the Device we don't have any versioning information available, so only the family property is set there. If we cannot find the family, they will default to Other.

The following methods are available:

Agent.toAgent();

Returns the family and version number concatinated in a nice human readable string.

var agent = useragent.parse(req.headers['user-agent']);
agent.toAgent(); // 'Chrome 15.0.874'

Agent.toString();

Returns the results of the Agent.toAgent() but also adds the parsed operating system to the string in a human readable format.

var agent = useragent.parse(req.headers['user-agent']);
agent.toString(); // 'Chrome 15.0.874 / Mac OS X 10.8.1'

// as it's a to string method you can also concat it with another string
'your useragent is ' + agent;
// 'your useragent is Chrome 15.0.874 / Mac OS X 10.8.1'

Agent.toVersion();

Returns the version of the browser in a human readable string.

var agent = useragent.parse(req.headers['user-agent']);
agent.toVersion(); // '15.0.874'

Agent.toJSON();

Generates a JSON representation of the Agent. By using the toJSON method we automatically allow it to be stringified when supplying as to the JSON.stringify method.

var agent = useragent.parse(req.headers['user-agent']);
agent.toJSON(); // returns an object

JSON.stringify(agent);

OperatingSystem.toString();

Generates a stringified version of operating system;

var agent = useragent.parse(req.headers['user-agent']);
agent.os.toString(); // 'Mac OSX 10.8.1'

OperatingSystem.toVersion();

Generates a stringified version of operating system's version;

var agent = useragent.parse(req.headers['user-agent']);
agent.os.toVersion(); // '10.8.1'

OperatingSystem.toJSON();

Generates a JSON representation of the OperatingSystem. By using the toJSON method we automatically allow it to be stringified when supplying as to the JSON.stringify method.

var agent = useragent.parse(req.headers['user-agent']);
agent.os.toJSON(); // returns an object

JSON.stringify(agent.os);

Device.toString();

Generates a stringified version of device;

var agent = useragent.parse(req.headers['user-agent']);
agent.device.toString(); // 'Asus A100'

Device.toVersion();

Generates a stringified version of device's version;

var agent = useragent.parse(req.headers['user-agent']);
agent.device.toVersion(); // '' , no version found but could also be '0.0.0'

Device.toJSON();

Generates a JSON representation of the Device. By using the toJSON method we automatically allow it to be stringified when supplying as to the JSON.stringify method.

var agent = useragent.parse(req.headers['user-agent']);
agent.device.toJSON(); // returns an object

JSON.stringify(agent.device);

Adding more features to the useragent

As I wanted to keep the core of the user agent parser as clean and fast as possible I decided to move some of the initially planned features to a new plugin file.

These extensions to the Agent prototype can be loaded by requiring the useragent/features file:

var useragent = require('useragent');
require('useragent/features');

The initial release introduces 1 new method, satisfies, which allows you to see if the version number of the browser satisfies a certain range. It uses the semver library to do all the range calculations but here is a small summary of the supported range styles:

  • >1.2.3 Greater than a specific version.
  • <1.2.3 Less than.
  • 1.2.3 - 2.3.4 := >=1.2.3 <=2.3.4.
  • ~1.2.3 := >=1.2.3 <1.3.0.
  • ~1.2 := >=1.2.0 <2.0.0.
  • ~1 := >=1.0.0 <2.0.0.
  • 1.2.x := >=1.2.0 <1.3.0.
  • 1.x := >=1.0.0 <2.0.0.

As it requires the semver module to function you need to install it seperately:

npm install semver --save

Agent.satisfies('range style here');

Check if the agent matches the supplied range.

var agent = useragent.parse(req.headers['user-agent']);
agent.satisfies('15.x || >=19.5.0 || 25.0.0 - 17.2.3'); // true
agent.satisfies('>16.12.0'); // false

Migrations

For small changes between version please review the changelog.

Upgrading from 1.10 to 2.0.0

  • useragent.fromAgent has been removed.
  • agent.toJSON now returns an Object, use JSON.stringify(agent) for the old behaviour.
  • agent.os is now an OperatingSystem instance with version numbers. If you still a string only representation do agent.os.toString().
  • semver has been removed from the dependencies, so if you are using the require('useragent/features') you need to add it to your own dependencies

Upgrading from 0.1.2 to 1.0.0

  • useragent.browser(ua) has been renamed to useragent.is(ua).
  • useragent.parser(ua, jsua) has been renamed to useragent.parse(ua, jsua).
  • result.pretty() has been renamed to result.toAgent().
  • result.V1 has been renamed to result.major.
  • result.V2 has been renamed to result.minor.
  • result.V3 has been renamed to result.patch.
  • result.prettyOS() has been removed.
  • result.match has been removed.

License

MIT

useragent's People

Contributors

3rd-eden avatar brandonaaron avatar c4milo avatar chalker avatar colinmutter avatar davidkwan95 avatar fintanf avatar irnc avatar joeyparrish avatar jonathanong avatar klall33 avatar klimashkin avatar mcollina avatar msemenistyi avatar pdehaan avatar sunknudsen avatar tobie avatar

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

useragent's Issues

Tests for the update process

The test suite is currently lacking tests for the update process and automatic updates. While it's not a critical component of the module it would prevent bugs like #30 to happen in the future.

Support IE 11

User agent string looks like this:

Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; rv:11.0) like Gecko

I use https://github.com/karma-runner/karma and it uses this module and it shows IE11 in a bad way.

Some new UA

Please add:

  • BingBot
  • SeznamBot
  • YandexBot
  • etc...
"Python-urllib/2.4",
"SeznamBot/3.0 (+http://fulltext.sblog.cz/)",
"Mozilla/5.0 (compatible; YandexBot/3.0; +http://yandex.com/bots)",
"GSLFbot",
"Mozilla/5.0 (compatible; Ezooms/1.0; [email protected])",
"Googlebot-Image/1.0",
"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)",
"Mozilla/5.0 (compatible; MJ12bot/v1.4.2; http://www.majestic12.co.uk/bot.php?+)",
"Mozilla/5.0 (compatible; TweetedTimes Bot/1.0; +http://tweetedtimes.com)",
"facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)",
"facebookplatform/1.0 (+http://developers.facebook.com)",
"EventMachine HttpClient",
"Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)",
"facebookexternalhit/1.0 (+http://www.facebook.com/externalhit_uatext.php)",
"Mozilla/5.0 (compatible; ltbot/1.3; [email protected])",
"DoCoMo/2.0 N905i(c100;TB;W24H16) (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)",
"Feedfetcher-Google; (+http://www.google.com/feedfetcher.html; 1 subscribers; feed-id=14515760453700115068)",
"SAMSUNG-SGH-E250/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Browser/6.2.3.3.c.1.101 (GUI) MMP/2.0 (compatible; Googlebot-Mobile/2.1; +http://www.google.com/bot.html)",
"Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)",
"msnbot-media/1.1 (+http://search.msn.com/msnbot.htm)",
"Mozilla/5.0 (compatible; 008/0.83; http://www.80legs.com/webcrawler.html) Gecko/2008032620",
"Mozilla/5.0 (compatible; discobot/2.0; +http://discoveryengine.com/discobot.html)",
"Mozilla/5.0 (compatible) Feedfetcher-Google; (+http://www.google.com/feedfetcher.html)",
"Java/1.6.0_24",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) Speedy Spider (http://www.entireweb.com/about/search_tech/speedy_spider/)",
"Mozilla/5.0 (X11; Linux x86_64) KHTML/4.8.1 (like Gecko) Konqueror/4.8",
"Mail.RU/2.0",
"TurnitinBot/2.1 (http://www.turnitin.com/robot/crawlerinfo.html)",
"Python-urllib/2.7",
"Mozilla/5.0 (compatible; oBot/2.3.1; +http://www-935.ibm.com/services/us/index.wss/detail/iss/a1029077?cntxt=a1027244)",
"Mozilla/5.0 (compatible; oBot/2.3.1; +http://filterdb.iss.net/crawler/)",
"Mozilla/5.0 (compatible; Exabot/3.0; +http://www.exabot.com/go/robot)",
"Mozilla/5.0 (compatible; AhrefsBot/3.0; +http://ahrefs.com/robot/)",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534+ (KHTML, like Gecko) BingPreview/1.0b",
"Mozilla/5.0 (compatible; OpenindexDeepSpider/Nutch-1.5-dev; +http://www.openindex.io/en/webmasters/spider.html)",
"Mozilla/5.0 (compatible; heritrix/1.14.3 +http://www.webarchiv.cz)",
"Mozilla/5.0 (compatible; Mail.RU/2.0)",
"Java/1.6.0_23",
"Mozilla/5.0 (compatible; TweetmemeBot/2.11; +http://tweetmeme.com/)",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en; rv:1.9.0.13) Gecko/2009073022 Firefox/3.5.2 (.NET CLR 3.5.30729) SurveyBot/2.3 (DomainTools)",
"Java/1.6.0_20",
"Mozilla/5.0 (compatible; DCPbot/1.2; +http://domains.checkparams.com/)",
"SEOstats 2.0.9          https://github.com/eyecatchup/SEOstats",
"Mozilla/5.0 (compatible; Plukkie/1.4; http://www.botje.com/plukkie.htm)",
"Mozilla/5.0 (compatible; Seznam screenshot-generator 2.0; +http://fulltext.sblog.cz/screenshot/)",
"Mozilla/5.0 (compatible; MJ12bot/v1.4.3; http://www.majestic12.co.uk/bot.php?+)",
"Java/1.6.0_31",
"Java/1.6.0_21",
"Googlebot-Video/1.0",
"Mozilla/5.0 (compatible; OpenindexShallowSpider/Nutch-1.5-dev; +http://www.openindex.io/en/webmasters/spider.html)",
"Java/1.7.0",
"Mozilla/4.77 [en] (X11; I; IRIX;64 6.5 IP30)",
"Java/1.6.0_02",
"Wotbox/2.0 ([email protected]; http://www.wotbox.com)",
"Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)",
"Mozilla/5.0 (compatible; AhrefsBot/2.0; +http://ahrefs.com/robot/)",
"UnwindFetchor/1.0 (+http://www.gnip.com/)",
"LinkedInBot/1.0 (compatible; Mozilla/5.0; Jakarta Commons-HttpClient/3.1 +http://www.linkedin.com)",
"MetaURI API/2.0 +metauri.com",
"Jolibot/1.0 (+http://www.jolicloud.com/)",
"Mozilla/5.0 (compatible; NetcraftSurveyAgent/1.0; [email protected])",
"Mozilla/5.0 (compatible; archive.org_bot +http://www.archive.org/details/archive.org_bot)",
"ShowyouBot (http://showyou.com/crawler)",
"Mozilla/5.0 (compatible; PaperLiBot/2.1; http://support.paper.li/entries/20023257-what-is-paper-li)",
"Java/1.6.0_16",
"netEstate NE Crawler (+http://www.sengine.info/)",
"Mozilla/5.0 (compatible; Jetslide; +http://jetsli.de/crawler)",
"percbotspider <[email protected]>",
"newsme/1.0; [email protected]",
"Mozilla/5.0 (compatible; YandexImages/3.0; +http://yandex.com/bots)",
"Mozilla/5.0 (compatible;picmole/1.0 +http://www.picmole.com)",
"Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"

useragent failed to check IE7

var useragent= require("useragent");

var agent = useragent.parse("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");

var ua= useragent.is("Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)");

result:
{
family: 'IE',
major: '7',
minor: '0',
patch: '0',
source: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'
}

{
chrome: false,
firefox: false,
ie: false,
mobile_safari: false,
mozilla: false,
opera: false,
safari: false,
webkit: false,
android: false,
version: '7.0'
}

Android Chrome not detected as mobile_safari

When using chrome from android device, even though 'mobile safari' is in the agent, it's not being parsed for useragent.is['mobile_safari'].

Also, this appears to work fine in useragent.parse as the family is Chrome Mobile. Some data below:

Mozilla/5.0 (Linux; Android 4.1.2; SC-06D Build/JZO54K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.92 Mobile Safari/537.36

useragent.is = { chrome: true,
firefox: false,
ie: false,
mobile_safari: false,
mozilla: false,
opera: false,
safari: false,
webkit: true,
version: '537.36' }

useragent.parse.family = family: Chrome Mobile

OS Version

Has OS version reporting been removed?

Opera is not recognised when using 'is'

When trying to identify the following user-agent (from Opera) i get different results

Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 OPR/26.0.1656.60

Using parse i get:

{ family: 'Opera',
  major: '26',
  minor: '0',
  patch: '1656',
  source: 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 OPR/26.0.1656.60' }

Using is i get:

{ chrome: true,
  firefox: false,
  ie: false,
  mobile_safari: false,
  mozilla: false,
  opera: false,
  safari: false,
  webkit: true,
  android: false,
  version: '537.36' }

iOS8 parse() crashes

Hi Arnout,

The Useragent string

"Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12A365 Safari/600.1.4"

crashes the parse() function.

I get:
[TypeError: Invalid Version: 8.0.undefined]

Cheers,
Joris

[bug] missing dependencies

hello there

i think you should add request and yamlparser to your dependencies in package.json.

these packages are needed when i'm paranoid with useragent(true); ...

4th+ parts of version discarded

Chrome version numbers go beyond major.minor.patch, like so:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36

...but useragent doesn't seem to allow the retrieval of the '.3' in the example above.

other useragents

I was thinking, if I was not on the list of useragent. Agent is created, it takes so?

var ua = useragent.is(req.headers['user-agent'])

// the object
{
  version: '3'
  webkit: false
  opera: false
  ie: false
  chrome: false
  safari: false
  mobile_safari: false
  firefox: false
  "my_UA" : true
}

Or as assessed other User Agents that are not existing?

IE11 addition timeline

Love this library, just curious what the typical timeline is to add a new browser like, say, Gecko-impersonating IE11?

make the 'satisfies' stuf a separate module.

It feels really awkward to require some 'features' file when you can just have a separate module to do the semver stuff given an Agent. You can also have semver be a hard dependency of that. I think it would be provide a better user experience. You could add the module to the readme if discoverability is a concern.

Problem with npm installation

root@randevu:/opt/nodejs# npm install useragent
npm WARN [email protected] package.json: bugs['web'] should probably be bugs['url']

[email protected] postinstall /opt/nodejs/node_modules/useragent
./bin/update.js

sh: ./bin/update.js: Permission denied
npm ERR! error installing [email protected] Error: [email protected] postinstall: ./bin/update.js
npm ERR! error installing [email protected] sh "-c" "./bin/update.js" failed with 126
npm ERR! error installing [email protected] at ChildProcess. (/usr/local/lib/node_modules/npm/lib/utils/exec.js:49:20)
npm ERR! error installing [email protected] at ChildProcess.emit (events.js:70:17)
npm ERR! error installing [email protected] at maybeExit (child_process.js:359:16)
npm ERR! error installing [email protected] at Process.onexit (child_process.js:395:5)
npm ERR! [email protected] postinstall: ./bin/update.js
npm ERR! sh "-c" "./bin/update.js" failed with 126
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is most likely a problem with the useragent package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ./bin/update.js
npm ERR! You can get their info via:
npm ERR! npm owner ls useragent
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Linux 2.6.24-29-virtual
npm ERR! command "node" "/usr/local/bin/npm" "install" "useragent"
npm ERR! cwd /opt/nodejs
npm ERR! node -v v0.6.3
npm ERR! npm -v 1.1.0-alpha-2
npm ERR! code ELIFECYCLE
npm ERR! message [email protected] postinstall: ./bin/update.js
npm ERR! message sh "-c" "./bin/update.js" failed with 126
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /opt/nodejs/npm-debug.log
npm not ok

curl support

not a huge deal but I noticed curl ended up as "other", probably common enough to consider a few executables maybe wget too

'satisfies' method sometimes failed

Hello!
If I have Opera 12.00, useragent returns me

{major: '12', minor: '00', patch: '0'}

And then semver 'satisfies' returns error

TypeError: Invalid Version: 12.00.0

because

Agent.prototype.satisfies = function satisfies (range) {
  return semver.satisfies(this.major + '.' + this.minor + '.' + this.patch, range);
};

Maybe it must be like this

Agent.prototype.satisfies = function satisfies (range) {
  return semver.satisfies((Number(this.major) || 0) + '.' + (Number(this.minor) || 0) + '.' + (Number(this.patch) || 0), range);
};

Broken device.family results since 2.1.4

I have two versions of my production server. Most are still on version 2.1.3, but one I built recently has 2.1.4. On this 2.1.4 server, there are some weird device.family results appearing in my logs. For example:

Samsung $2
ZiiLABS $2
Prestigio PMP3970B $2
Lenovo IdeaTab $2
Samsung undefined$2
Samsung SAMSUNG $2
LG-$2
HTC One $2 $3 $4
HTC Desire $2 $3 $4
Nokia$2$3
Yifang GE$2$3
HTC WildfireS $2 $3 $4

Picking the top one as an example, the user agent is

Mozilla/5.0 (Linux; Android 4.4.2; en-gb; SAMSUNG SM-T230 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/1.5 Chrome/28.0.1500.94 Safari/537.36

Using 2.1.3, device.family is correct: Samsung SM-T230
Using 2.1.4, device.family is incorrect: Samsung $2

90% of devices are OK. These broken ones represent around 10% of the different devices in my logs. I have not noticed any similar issues with browser or operating system. It just looks like device that's a bit broken.

I'm going to force 2.1.3 for the moment on my servers, but hopefully this can be fixed going forward :-)

Project license

Can you clarify what is the license you are using for your project.

https://github.com/3rd-Eden/useragent/blob/master/LICENSE
I see that you have declared that you are using regex code that is BSD licensed and Node.js code that is MIT licensed. But what is the license for Useragent itself? Either BSD or MIT would be great, but I'm unsure which you mean it to be.

Let me suggest that you put the contents of the LICENSE file into a CREDITS files (since you are giving credit to the projects you are using), and then put a license in the LICENSE file. You can use the following templates

MIT License
Copyright (c) [YEAR] [The name of the copyright holder]. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining... etc. etc.

or
BSD License
Copyright (c) [INSERT YEAR], [The name of the copyright holder]. All rights reserved.

Redistribution and use of this software in source and binary forms, with or without modification, are permitted... etc. etc.

Cannot find module 'semver'

I was rebuilding an app today that uses 3rd-Eden/useragent when I was surprised to find an error because of a missing module:

module.js:340
    throw err;
    ^
Error: Cannot find module 'semver'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/node_modules/useragent/features/index.js:7:14)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)

The whole point of packages.json, as I understand, is to maintain consistency and define dependencies for modules to precisely avoid this issue.

Since semver is now a requirement of the package, shouldn't it be added to

"dependencies": { ... }

in the package.json for this module?

Problem with npm installation in win xp sp3

ERR! [email protected] postinstall: ./bin/update.js
ERR! cmd "/c" "./bin/update.js" failed with 1
ERR!
ERR! Failed at the [email protected] postinstall script.
ERR! This is most likely a problem with the useragent package,
ERR! not with npm itself.
ERR! Tell the author that this fails on your system:
ERR! ./bin/update.js
ERR! You can get their info via:
ERR! npm owner ls useragent
ERR! There is likely additional logging output above.
ERR!
ERR! System Windows_NT 5.1.2600
ERR! command "C:\Archivos de programa\nodejs\node.exe" "C:\Archivos de programa\nodejs\node_modules\npm\bin\npm-cli.js" "install" "useragent"
ERR! cwd C:\workspace\mytest
ERR! node -v v0.6.6
ERR! npm -v 1.1.0-beta-7
ERR! code ELIFECYCLE
ERR! message [email protected] postinstall: ./bin/update.js
ERR! message cmd "/c" "./bin/update.js" failed with 1
verbose exit [ 1, true ]

Problem with capitalization

I use the library to parse huge amounts of useragents. Sometimes I get lists of decapitalized (ie all small letters) useragents. The Parser doesn't pick them up. Is there a way to add that functionality?

PhantomJS is not detected correct

Given the following user agent string:

Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.6.0 Safari/534.34

This is the result

{ family: 'Safari',
  major: '0',
  minor: '0',
  patch: '0',
  source: 'Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.6.0 Safari/534.34' }

But it should be

{ family: 'PhantomJS',
  major: '1',
  minor: '6',
  patch: '0',
  source: 'Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.6.0 Safari/534.34' }

No version info for Windows OS

Different Windows OS versions return inconsistent results for the os parameter. And as far as I can tell, none of them return the actual version of the OS, they are all 0.0.0

This string returns the family as 'Windows 8.1', with versions as 0.0.0

useragent.parse('Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko').os
{ family: 'Windows 8.1',
  major: '0',
  minor: '0',
  patch: '0' }

While this string returns family as just Windows.

useragent.parse('Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.4; Trident/7.0; rv:11.0) like Gecko').os
{ family: 'Windows',
  major: '0',
  minor: '0',
  patch: '0' }

In both cases, version information is invalid, and the name of the OS varies. I think the name should always be "Windows", and the version info should properly updated.

Any way to see comprehensive list of browser families, os?

Hello-

Not a bug, but just a question for usability of the useragent module. Is there any way that I can see a list of all of the families and oses that can be reported by the useragent module? I know I can try to figure this out via the regex, but is there an easier way?

Thanks!
Matt

Engine parse?

Hello! It would be great if engine will parse. Something like:

{ name: 'WebKit', version: '537.71' }
{ name: 'Trident', version: '7.0' }

Fix .npmignore

Right now is ignoring "tests" but the directory is actually called "test" and it's not being ignored.

UserAgent For SlimerJS

Please add the following UserAgent to the list
Mozilla/5.0 (X11; Linux x86_64; rv:21.0) Gecko/20100101 SlimerJS/0.7

it is from a scriptable browser for Web developers slimerjs (http://slimerjs.org)

for him, I used the following regular expression in a file useragent/lib/regexps.js

parser = Object.create(null);
parser[0] = new RegExp("(SlimerJS)/(\d+).(\d+).(\d+)");
parser[1] = 0;
parser[2] = 0;
parser[3] = 0;
parser[4] = 0;
exports.browser[159] = parser;

Android 4.4.2 incorrectly detected Chrome 30.0.0

Problem

On an Android 4.4.2 device, the .toAgent() function returns Chrome 30.0.0 instead of Android.

Reproducible on

  • Nexus 5 (4.4.2)
    • Mozilla/5.0 (Linux; Android 4.4.2; Nexus 5 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36
  • Nexus 7 (4.4.2)
    • Mozilla/5.0 (Linux; Android 4.4.2; Nexus 7 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Safari/537.36

Argh, user-agents! :)

prettyOs for FF3.6 on Mac OS X incorrect

For this User-Agent:
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 GTB7.1"

pretty() --> "Firefox 3.6.13"
prettyOs() --> "Firefox 3.6.13"

should be "OS X 10.6.4"

useragent strings that contain multiple "Windows NT" versions are not handled properly

Some useragent strings contain more than one "Windows NT" version.

For example (this is an actual useragent string):

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; Zune 4.0; .NET CLR 1.

Note that there is present both "Windows NT 6.1" and "Windows NT 5.1".

Currently, the useragent module reports this the OS for this as "Windows XP", when in fact it should be "Windows 7".

The fix here is to order the "Windows NT" regexes so that Windows versions are searched for in order from highest version to lowest version (since only the highest "Windows NT" string should be regarded).

I'll open a pull request for this now.

ipod using iOS 4 seems to be wrongly parsed.

ua.parse('Mozilla/5.0 (iPod; U; CPU iPhone OS 4_2_1 like Mac OS X; hu-hu) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5') 

{ family: 'iPod',
  major: '5',
  minor: '0',
  patch: '2',
  os: 'iOS' }

Expected

{ family: 'iPod',
  major: '4',
  minor: '2',
  patch: '1',
  os: 'iOS' }

Firefox is shown as IE

Hi,

having this useragent string:
var ua = Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0

The returning object of 'useragent.is(ua)' is:
{"version":"8.0","webkit":false,"opera":false,"ie":true,"chrome":false,"safari":false,"mobile_safari":false,"firefox":true}

Firefox is flaged correctly as true, but the IE is also flaged as true.
That's not right.. :)

So, for now i am using the 'parse'-function and going over the browsers family value to determine the browsertype.

Great module indeed, thanx.

Felix

Wrong Internet Explorer parsing

results of useragent.is:
{ ua:
{ version: '535.2',
webkit: true,
opera: false,
ie: true,
chrome: true,
safari: false,
mobile_safari: false,
firefox: false } }

It's from Google Chrome. Ie is set to true. Guess something wrong inside parser.

Please fix it. I like the simplicity of your module.

update dependencies only available in dev

Dependencies used for updating are only available as devDependencies (request, yamlparser,...).

This way, it is "not possible" to use useragent() in a production environment. Of course it is not an everyday use-case, but I was wondering if this is done on purpose?

Mac device recognized as other

Hi, thanks for the great module, really enjoy it. Quick question, the following UA string:

'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36',

results in the device being set to 'Other', what are your thoughts about it containing Macintosh or Desktop since that is the 'device' the user is actually using?

[bug] TypeError: Cannot read property 'length' of undefined

Looks like your latest release introduced a new bug:

/home/michael.heuberger/projects/binarykitchen/code/videomail/node_modules/useragent/index.js:13
  , osparserslength = osparsers.length;
                               ^
TypeError: Cannot read property 'length' of undefined
    at Object.<anonymous> (/home/michael.heuberger/projects/binarykitchen/code/videomail/node_modules/useragent/index.js:13:32)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/michael.heuberger/projects/binarykitchen/code/videomail/app/lib/util/useragent.js:3:17)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

Process finished with exit code 8

Any change you can fix that pretty soon? Thanks!

GoogleBot identified as something else

The following user agent string is identified as something else instead of Googlebot.
Now i know that i can look into the device and see that its a Spider but i believe that the useragent itself should be Googlebot

Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:21.0; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27 Chrome/27.0.1453.94 Gecko/20100101 Firefox/21.0 Googlebot/2.1 (+http://www.googlebot.com/bot.html)
Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36 compatible; Googlebot/2.1; +http://www.google.com/bot.html

is there any way to generate user agents?

let's say I wanted to send user agents with my requests, and I wanted to simulate browser traffic. For example, lets say I'm testing my site's analytics and want 24.3 % of my requests to come from chrome 20, 15% from ie8, etc. Is there a way I can use this library to produce user agents, rather than consuming them?

Crash in useragent.match() call

I'm running version 1.01 and getting this crash occasionally:

/home/niek/node_modules/useragent/lib/useragent.js:117
    if (ua = useragent.match(browsers[i].r)) {
                       ^
TypeError: Cannot call method 'match' of undefined
    at Function.parse (/home/niek/node_modules/useragent/lib/useragent.js:117:24)   
    at IncomingMessage.<anonymous> (/home/niek/myscript.js:34:26)
    at IncomingMessage.emit (events.js:61:17)
    at HTTPParser.onMessageComplete (http.js:133:23)
    at Socket.ondata (http.js:1029:22)
    at Socket._onReadable (net.js:677:27)
    at IOWatcher.onReadable [as callback] (net.js:177:10)

The code in question:
var ua = useragent.parse(req.headers['user-agent']);

Is this because req.headers['user-agent'] is undefined if no user-agent is included in the HTTP request?

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.