mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 16:08:47 +03:00
Fix #643 - Improve iOS detection + detect Slack (&Slackbot)
This commit is contained in:
parent
c3be7326b8
commit
29fb85658a
@ -15,10 +15,19 @@ const VERSION = 'version';
|
||||
const MOBILE = 'mobile';
|
||||
const TABLET = 'tablet';
|
||||
|
||||
const Apps = Object.freeze({
|
||||
browser : [
|
||||
[/chatlyio\/([\d\.]+)/i], [VERSION, 'Slack', [TYPE, 'app']]
|
||||
]
|
||||
});
|
||||
|
||||
const Bots = Object.freeze({
|
||||
browser : [
|
||||
// Googlebot / BingBot / MSNBot / FacebookBot
|
||||
[/((?:google|bing|msn|facebook)bot(?:\-[imagevdo]{5})?|bingpreview)\/([\w\.]+)/i], [NAME, VERSION, [TYPE, 'bot']]
|
||||
[/((?:google|bing|msn|facebook)bot(?:\-[imagevdo]{5})?|bingpreview)\/([\w\.]+)/i], [NAME, VERSION, [TYPE, 'bot']],
|
||||
|
||||
// Slackbot - https://api.slack.com/robots
|
||||
[/(slack(?:bot)?(?:-imgproxy|-linkexpanding)?) ([\w\.]+)/i], [NAME, VERSION, [TYPE, 'bot']]
|
||||
]
|
||||
});
|
||||
|
||||
@ -107,16 +116,17 @@ const Emails = Object.freeze({
|
||||
]
|
||||
});
|
||||
|
||||
const Tools = Object.freeze({
|
||||
const CLI = Object.freeze({
|
||||
browser : [
|
||||
// wget / curl / lynx
|
||||
[/(wget|curl|lynx)\/([\w\.]+)/i], [NAME, VERSION, [TYPE, 'tool']]
|
||||
[/(wget|curl|lynx)\/([\w\.]+)/i], [NAME, VERSION, [TYPE, 'cli']]
|
||||
]
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
Apps,
|
||||
Bots,
|
||||
ExtraDevices,
|
||||
Emails,
|
||||
Tools
|
||||
CLI
|
||||
};
|
@ -732,7 +732,7 @@
|
||||
|
||||
// iOS/macOS
|
||||
/ip[honead]{2,4}\b(?:.*os ([\w]+) like mac|; opera)/i, // iOS
|
||||
/ios;fbsv\/([\d\.]+)/i,
|
||||
/(?:ios;fbsv\/|iphone.+ios[\/ ])([\d\.]+)/i,
|
||||
/cfnetwork\/.+darwin/i
|
||||
], [[VERSION, /_/g, '.'], [NAME, 'iOS']], [
|
||||
/(mac os x) ?([\w\. ]*)/i,
|
||||
|
@ -1,7 +1,7 @@
|
||||
const assert = require('assert');
|
||||
const safeRegex = require('safe-regex');
|
||||
const UAParser = require('ua-parser-js');
|
||||
const { Bots, Emails, Tools } = require('ua-parser-js/extensions');
|
||||
const { Bots, Emails, CLI } = require('ua-parser-js/extensions');
|
||||
|
||||
describe('Bots', () => {
|
||||
it('Can detect bots', () => {
|
||||
@ -20,11 +20,11 @@ describe('Bots', () => {
|
||||
assert.deepEqual(botParser.setUA(bingPreview).getBrowser(), {name: "BingPreview", version: "1.0b", major: "1", type: "bot"});
|
||||
assert.deepEqual(botParser.setUA(opera).getBrowser(), {name: "Opera", version: "8.5", major: "8"});
|
||||
|
||||
// try merging Bots & Tools
|
||||
const botsAndTools = { browser : [...Bots.browser, ...Tools.browser]};
|
||||
const botolParser = new UAParser(botsAndTools);
|
||||
assert.deepEqual(botolParser.setUA(wget).getBrowser(), {name: "Wget", version: "1.21.1", major: "1", type:"tool"});
|
||||
assert.deepEqual(botolParser.setUA(facebookBot).getBrowser(), {name: "FacebookBot", version: "1.0", major: "1", type:"bot"});
|
||||
// try merging Bots & CLIs
|
||||
const botsAndCLIs = { browser : [...Bots.browser, ...CLI.browser]};
|
||||
const botsAndCLIsParser = new UAParser(botsAndCLIs);
|
||||
assert.deepEqual(botsAndCLIsParser.setUA(wget).getBrowser(), {name: "Wget", version: "1.21.1", major: "1", type:"cli"});
|
||||
assert.deepEqual(botsAndCLIsParser.setUA(facebookBot).getBrowser(), {name: "FacebookBot", version: "1.0", major: "1", type:"bot"});
|
||||
|
||||
const emailParser = new UAParser(Emails);
|
||||
assert.deepEqual(emailParser.setUA(outlook).getBrowser(), {name: "Microsoft Outlook", version: "16.0.9126", major: "16", type: "email"});
|
||||
|
@ -773,6 +773,15 @@
|
||||
"version" : "13.6.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc": "iOS with Slack App",
|
||||
"ua": "com.tinyspeck.chatlyio/23.04.10 (iPhone; iOS 16.4.1; Scale/3.00)",
|
||||
"expect":
|
||||
{
|
||||
"name" : "iOS",
|
||||
"version" : "16.4.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"desc" : "watchOS",
|
||||
"ua" : "server-bag [Watch OS,8.4,19S546,Watch3,4]",
|
||||
|
Loading…
x
Reference in New Issue
Block a user