Skip to content

Commit

Permalink
Add new browser: Ladybird
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalman committed Dec 8, 2024
1 parent d024fe2 commit 592bfdd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/enums/ua-parser-enums.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const Browser = Object.freeze({
KLARNA: 'Klarna',
KINDLE: 'Kindle',
LENOVO: 'Smart Lenovo Browser',
LADYBIRD: 'Ladybird',
LIBREWOLF: 'LibreWolf',
LIEBAO: 'LBBROWSER',
LINE: 'Line',
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/ua-parser-helpers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Project: https://github.com/faisalman/ua-parser-js
// Definitions by: Faisal Salman <https://github.com/faisalman>

import { IResult } from "../main/ua-parser";
import type { IResult } from "../main/ua-parser";

declare function getDeviceVendor(model: string): string | undefined;
declare function isAppleSilicon(resultOrUA: IResult | string): boolean;
Expand Down
53 changes: 37 additions & 16 deletions src/main/ua-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,47 @@
// Constants
/////////////

var LIBVERSION = '2.0.0',
var LIBVERSION = '2.0.0', // UAParser.version
UA_MAX_LENGTH = 500, // UA string over this length will be trimmed
USER_AGENT = 'user-agent',
EMPTY = '',
UNKNOWN = '?',

// typeof
FUNC_TYPE = 'function',
UNDEF_TYPE = 'undefined',
OBJ_TYPE = 'object',
STR_TYPE = 'string',
MAJOR = 'major',
MODEL = 'model',

// properties
UA_BROWSER = 'browser',
UA_CPU = 'cpu',
UA_DEVICE = 'device',
UA_ENGINE = 'engine',
UA_OS = 'os',
UA_RESULT = 'result',

NAME = 'name',
TYPE = 'type',
VENDOR = 'vendor',
VERSION = 'version',
ARCHITECTURE= 'architecture',
MAJOR = 'major',
MODEL = 'model',

// device types
CONSOLE = 'console',
MOBILE = 'mobile',
TABLET = 'tablet',
SMARTTV = 'smarttv',
WEARABLE = 'wearable',
XR = 'xr',
EMBEDDED = 'embedded',

// browser types
INAPP = 'inapp',
USER_AGENT = 'user-agent',
UA_MAX_LENGTH = 500,

// client hints
BRANDS = 'brands',
FORMFACTORS = 'formFactors',
FULLVERLIST = 'fullVersionList',
Expand All @@ -59,12 +76,8 @@
CH_HEADER_PLATFORM = CH_HEADER + '-' + PLATFORM,
CH_HEADER_PLATFORM_VER = CH_HEADER_PLATFORM + '-version',
CH_ALL_VALUES = [BRANDS, FULLVERLIST, MOBILE, MODEL, PLATFORM, PLATFORMVER, ARCHITECTURE, FORMFACTORS, BITNESS],
UA_BROWSER = 'browser',
UA_CPU = 'cpu',
UA_DEVICE = 'device',
UA_ENGINE = 'engine',
UA_OS = 'os',
UA_RESULT = 'result',

// device vendors
AMAZON = 'Amazon',
APPLE = 'Apple',
ASUS = 'ASUS',
Expand All @@ -83,8 +96,8 @@
SONY = 'Sony',
XIAOMI = 'Xiaomi',
ZEBRA = 'Zebra',
PREFIX_MOBILE = 'Mobile ',
SUFFIX_BROWSER = ' Browser',

// browsers
CHROME = 'Chrome',
CHROMIUM = 'Chromium',
CHROMECAST = 'Chromecast',
Expand All @@ -93,6 +106,11 @@
OPERA = 'Opera',
FACEBOOK = 'Facebook',
SOGOU = 'Sogou',

PREFIX_MOBILE = 'Mobile ',
SUFFIX_BROWSER = ' Browser',

// os
WINDOWS = 'Windows';

var isWindow = typeof window !== UNDEF_TYPE,
Expand Down Expand Up @@ -464,8 +482,8 @@
/(mozilla)\/([\w\.]+) .+rv\:.+gecko\/\d+/i, // Mozilla

// Other
/(polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf|obigo|mosaic|(?:go|ice|up)[\. ]?browser)[-\/ ]?v?([\w\.]+)/i,
// Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Obigo/Mosaic/Go/ICE/UP.Browser
/(amaya|dillo|doris|icab|ladybird|lynx|mosaic|netsurf|obigo|polaris|w3m|(?:go|ice|up)[\. ]?browser)[-\/ ]?v?([\w\.]+)/i,
// Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf/Obigo/Mosaic/Go/ICE/UP.Browser/Ladybird
/\b(links) \(([\w\.]+)/i // Links
], [NAME, [VERSION, /_/g, '.']], [

Expand Down Expand Up @@ -855,8 +873,11 @@
/ekioh(flow)\/([\w\.]+)/i, // Flow
/(khtml|tasman|links)[\/ ]\(?([\w\.]+)/i, // KHTML/Tasman/Links
/(icab)[\/ ]([23]\.[\d\.]+)/i, // iCab
/\b(libweb)/i

/\b(libweb)/i // LibWeb
], [NAME, VERSION], [
/ladybird\//i
], [[NAME, 'LibWeb']], [

/rv\:([\w\.]{1,9})\b.+(gecko)/i // Gecko
], [VERSION, NAME]
Expand Down
10 changes: 10 additions & 0 deletions test/data/ua/browser/browser-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,16 @@
"major" : "91"
}
},
{
"desc" : "Ladybird",
"ua" : "Mozilla/5.0 (Linux; x86_64) Ladybird/1.0",
"expect" :
{
"name" : "Ladybird",
"version" : "1.0",
"major" : "1"
}
},
{
"desc" : "LibreWolf",
"ua" : "Mozilla/5.0 (X11; Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0 LibreWolf/97.0.1",
Expand Down
9 changes: 9 additions & 0 deletions test/data/ua/engine/engine-all.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@
"version" : "4.5.4"
}
},
{
"desc" : "LibWeb",
"ua" : "Mozilla/5.0 (Linux; x86_64) Ladybird/1.0",
"expect" :
{
"name" : "LibWeb",
"version" : "undefined"
}
},
{
"desc" : "LibWeb",
"ua" : "Mozilla/4.0 (SerenityOS; x86) LibWeb+LibJS (Not KHTML, nor Gecko) LibWeb",
Expand Down

0 comments on commit 592bfdd

Please sign in to comment.