From b09878934fce1de9bcadace72cc3a6fd6c613e34 Mon Sep 17 00:00:00 2001 From: Faisal Salman Date: Wed, 29 Mar 2023 22:52:56 +0700 Subject: [PATCH] Prevent altering the result when supplied user-agent is different from current user-agent --- dist/ua-parser.min.js | 2 +- dist/ua-parser.pack.js | 2 +- readme.md | 2 +- src/ua-parser.js | 9 +++++---- src/ua-parser.mjs | 9 +++++---- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/dist/ua-parser.min.js b/dist/ua-parser.min.js index 2936c2e63..9bba36131 100644 --- a/dist/ua-parser.min.js +++ b/dist/ua-parser.min.js @@ -1,4 +1,4 @@ /* UAParser.js v2.0.0-alpha.1 Copyright © 2012-2023 Faisal Salman MIT License */ -(function(window,undefined){"use strict";var LIBVERSION="2.0.0-alpha.1",EMPTY="",UNKNOWN="?",FUNC_TYPE="function",UNDEF_TYPE="undefined",OBJ_TYPE="object",STR_TYPE="string",MAJOR="major",MODEL="model",NAME="name",TYPE="type",VENDOR="vendor",VERSION="version",ARCHITECTURE="architecture",CONSOLE="console",MOBILE="mobile",TABLET="tablet",SMARTTV="smarttv",WEARABLE="wearable",EMBEDDED="embedded",USER_AGENT="user-agent",UA_MAX_LENGTH=350,BRANDS="brands",FULLVERLIST="fullVersionList",PLATFORM="platform",PLATFORMVER="platformVersion",BITNESS="bitness",CH_HEADER="sec-ch-ua",CH_HEADER_FULL_VER_LIST=CH_HEADER+"-full-version-list",CH_HEADER_ARCH=CH_HEADER+"-arch",CH_HEADER_BITNESS=CH_HEADER+"-bitness",CH_HEADER_MOBILE=CH_HEADER+"-mobile",CH_HEADER_MODEL=CH_HEADER+"-model",CH_HEADER_PLATFORM=CH_HEADER+"-platform",CH_HEADER_PLATFORM_VER=CH_HEADER_PLATFORM+"-version",CH_ALL_VALUES=["brands","fullVersionList",MOBILE,MODEL,"platform","platformVersion",ARCHITECTURE,"bitness"],UA_BROWSER="browser",UA_CPU="cpu",UA_DEVICE="device",UA_ENGINE="engine",UA_OS="os",UA_RESULT="result",AMAZON="Amazon",APPLE="Apple",ASUS="ASUS",BLACKBERRY="BlackBerry",GOOGLE="Google",HUAWEI="Huawei",LG="LG",MICROSOFT="Microsoft",MOTOROLA="Motorola",SAMSUNG="Samsung",SHARP="Sharp",SONY="Sony",XIAOMI="Xiaomi",ZEBRA="Zebra",PREFIX_MOBILE="Mobile ",SUFFIX_BROWSER=" Browser",CHROME="Chrome",EDGE="Edge",FIREFOX="Firefox",OPERA="Opera",FACEBOOK="Facebook",WINDOWS="Windows";var NAVIGATOR=typeof window!==UNDEF_TYPE&&window.navigator?window.navigator:undefined,NAVIGATOR_UADATA=NAVIGATOR&&NAVIGATOR.userAgentData?NAVIGATOR.userAgentData:undefined;var assignFromEntries=function(arr){for(var i in arr){var propName=arr[i];if(typeof propName==OBJ_TYPE&&propName.length==2){this[propName[0]]=propName[1]}else{this[propName]=undefined}}return this},extend=function(regexes,extensions){var mergedRegexes={};for(var i in regexes){mergedRegexes[i]=extensions[i]&&extensions[i].length%2===0?extensions[i].concat(regexes[i]):regexes[i]}return mergedRegexes},enumerize=function(arr){var enums={};for(var i=0;i0){for(var i in str1){if(lowerize(str1[i])==lowerize(str2))return true}return false}return typeof str1===STR_TYPE?lowerize(str2).indexOf(lowerize(str1))!==-1:false},isExtensions=function(obj){for(var prop in obj){return/^(browser|cpu|device|engine|os)$/.test(prop)}},itemListToArray=function(header){if(!header)return undefined;var arr=[];var tokens=strip(/\\?\"/g,header).split(", ");for(var i=0;i0){if(q.length===2){if(typeof q[1]==FUNC_TYPE){this[q[0]]=q[1].call(this,match)}else{this[q[0]]=q[1]}}else if(q.length===3){if(typeof q[1]===FUNC_TYPE&&!(q[1].exec&&q[1].test)){this[q[0]]=match?q[1].call(this,match,q[2]):undefined}else{this[q[0]]=match?match.replace(q[1],q[2]):undefined}}else if(q.length===4){this[q[0]]=match?q[3].call(this,match.replace(q[1],q[2])):undefined}}else{this[q]=match?match:undefined}}}}i+=2}},strMapper=function(str,map){for(var i in map){if(typeof map[i]===OBJ_TYPE&&map[i].length>0){for(var j=0;j2){this.set(MODEL,"iPad").set(TYPE,TABLET)}break;case UA_OS:if(!this.get(NAME)&&NAVIGATOR_UADATA&&NAVIGATOR_UADATA[PLATFORM]&&NAVIGATOR_UADATA[PLATFORM]!="Unknown"){this.set(NAME,NAVIGATOR_UADATA[PLATFORM])}break;case UA_RESULT:var createUAParserItem=function(itemType){return new UAParserItem(itemType,ua,rgxMap[itemType],uaCH).get()};this.set("ua",ua).set(UA_BROWSER,createUAParserItem(UA_BROWSER)).set(UA_CPU,createUAParserItem(UA_CPU)).set(UA_DEVICE,createUAParserItem(UA_DEVICE)).set(UA_ENGINE,createUAParserItem(UA_ENGINE)).set(UA_OS,createUAParserItem(UA_OS)).get()}return this}UAParserItem.prototype.get=function(prop){if(!prop)return this.data;return this.data.hasOwnProperty(prop)?this.data[prop]:undefined};UAParserItem.prototype.parse=function(){if(this.itemType!=UA_RESULT){rgxMapper.call(this.data,this.ua,this.rgxMap)}return this};UAParserItem.prototype.parseCH=function(){var ua=this.ua,uaCH=this.uaCH,rgxMap=this.rgxMap;switch(this.itemType){case UA_BROWSER:var brands=uaCH[FULLVERLIST]||uaCH[BRANDS];if(brands){for(var i in brands){var brandName=brands[i].brand,brandVersion=brands[i].version;if(!/not.a.brand/i.test(brandName)||/chromi/i.test(this.get(NAME))){this.set(NAME,strip(GOOGLE+" ",brandName)).set(VERSION,brandVersion).set(MAJOR,majorize(brandVersion))}}}break;case UA_CPU:var archName=uaCH[ARCHITECTURE];if(archName){if(archName&&uaCH[BITNESS]=="64")archName+="64";rgxMapper.call(this.data,archName+";",rgxMap)}break;case UA_DEVICE:if(uaCH[MOBILE]){this.set(TYPE,MOBILE)}if(uaCH[MODEL]){this.set(MODEL,uaCH[MODEL])}break;case UA_OS:var osName=uaCH[PLATFORM];if(osName){var osVersion=uaCH[PLATFORMVER];if(osName==WINDOWS)osVersion=parseInt(majorize(osVersion),10)>=13?"11":"10";this.set(NAME,osName).set(VERSION,osVersion)}break;case UA_RESULT:var createUAParserItemWithCH=function(itemType){return new UAParserItem(itemType,ua,rgxMap[itemType],uaCH).parseCH().get()};this.set("ua",ua).set(UA_BROWSER,createUAParserItemWithCH(UA_BROWSER)).set(UA_CPU,createUAParserItemWithCH(UA_CPU)).set(UA_DEVICE,createUAParserItemWithCH(UA_DEVICE)).set(UA_ENGINE,createUAParserItemWithCH(UA_ENGINE)).set(UA_OS,createUAParserItemWithCH(UA_OS))}return this};UAParserItem.prototype.set=function(prop,val){this.data[prop]=val;return this};function UAParser(ua,extensions,headers){if(typeof ua===OBJ_TYPE){if(isExtensions(ua)){if(typeof extensions===OBJ_TYPE){headers=extensions}extensions=ua}else{headers=ua;extensions=undefined}ua=undefined}else if(typeof ua===STR_TYPE&&!isExtensions(extensions)){headers=extensions;extensions=undefined}if(!(this instanceof UAParser)){return new UAParser(ua,extensions,headers).getResult()}var userAgent=ua||(NAVIGATOR&&NAVIGATOR.userAgent?NAVIGATOR.userAgent:headers&&headers[USER_AGENT]?headers[USER_AGENT]:EMPTY),HTTP_UACH=new UAParserDataCH(headers,true),regexMap=extensions?extend(defaultRegexes,extensions):defaultRegexes,createUAParserItemFunc=function(itemType){return function(){return new UAParserItem(itemType,userAgent,itemType==UA_RESULT?regexMap:regexMap[itemType],HTTP_UACH).get()}};assignFromEntries.call(this,[["getBrowser",createUAParserItemFunc(UA_BROWSER)],["getCPU",createUAParserItemFunc(UA_CPU)],["getDevice",createUAParserItemFunc(UA_DEVICE)],["getEngine",createUAParserItemFunc(UA_ENGINE)],["getOS",createUAParserItemFunc(UA_OS)],["getResult",createUAParserItemFunc(UA_RESULT)],["getUA",function(){return userAgent}],["setUA",function(ua){userAgent=typeof ua===STR_TYPE&&ua.length>UA_MAX_LENGTH?trim(ua,UA_MAX_LENGTH):ua;return this}]]).setUA(userAgent);return this}UAParser.VERSION=LIBVERSION;UAParser.BROWSER=enumerize([NAME,VERSION,MAJOR]);UAParser.CPU=enumerize([ARCHITECTURE]);UAParser.DEVICE=enumerize([MODEL,VENDOR,TYPE,CONSOLE,MOBILE,SMARTTV,TABLET,WEARABLE,EMBEDDED]);UAParser.ENGINE=UAParser.OS=enumerize([NAME,VERSION]);if(typeof exports!==UNDEF_TYPE){if(typeof module!==UNDEF_TYPE&&module.exports){exports=module.exports=UAParser}exports.UAParser=UAParser}else{if(typeof define===FUNC_TYPE&&define.amd){define(function(){return UAParser})}else if(typeof window!==UNDEF_TYPE){window.UAParser=UAParser}}var $=typeof window!==UNDEF_TYPE&&(window.jQuery||window.Zepto);if($&&!$.ua){var parser=new UAParser;$.ua=parser.getResult();$.ua.get=function(){return parser.getUA()};$.ua.set=function(ua){parser.setUA(ua);var result=parser.getResult();for(var prop in result){$.ua[prop]=result[prop]}}}})(typeof window==="object"?window:this); \ No newline at end of file +(function(window,undefined){"use strict";var LIBVERSION="2.0.0-alpha.1",EMPTY="",UNKNOWN="?",FUNC_TYPE="function",UNDEF_TYPE="undefined",OBJ_TYPE="object",STR_TYPE="string",MAJOR="major",MODEL="model",NAME="name",TYPE="type",VENDOR="vendor",VERSION="version",ARCHITECTURE="architecture",CONSOLE="console",MOBILE="mobile",TABLET="tablet",SMARTTV="smarttv",WEARABLE="wearable",EMBEDDED="embedded",USER_AGENT="user-agent",UA_MAX_LENGTH=350,BRANDS="brands",FULLVERLIST="fullVersionList",PLATFORM="platform",PLATFORMVER="platformVersion",BITNESS="bitness",CH_HEADER="sec-ch-ua",CH_HEADER_FULL_VER_LIST=CH_HEADER+"-full-version-list",CH_HEADER_ARCH=CH_HEADER+"-arch",CH_HEADER_BITNESS=CH_HEADER+"-bitness",CH_HEADER_MOBILE=CH_HEADER+"-mobile",CH_HEADER_MODEL=CH_HEADER+"-model",CH_HEADER_PLATFORM=CH_HEADER+"-platform",CH_HEADER_PLATFORM_VER=CH_HEADER_PLATFORM+"-version",CH_ALL_VALUES=["brands","fullVersionList",MOBILE,MODEL,"platform","platformVersion",ARCHITECTURE,"bitness"],UA_BROWSER="browser",UA_CPU="cpu",UA_DEVICE="device",UA_ENGINE="engine",UA_OS="os",UA_RESULT="result",AMAZON="Amazon",APPLE="Apple",ASUS="ASUS",BLACKBERRY="BlackBerry",GOOGLE="Google",HUAWEI="Huawei",LG="LG",MICROSOFT="Microsoft",MOTOROLA="Motorola",SAMSUNG="Samsung",SHARP="Sharp",SONY="Sony",XIAOMI="Xiaomi",ZEBRA="Zebra",PREFIX_MOBILE="Mobile ",SUFFIX_BROWSER=" Browser",CHROME="Chrome",EDGE="Edge",FIREFOX="Firefox",OPERA="Opera",FACEBOOK="Facebook",WINDOWS="Windows";var NAVIGATOR=typeof window!==UNDEF_TYPE&&window.navigator?window.navigator:undefined,NAVIGATOR_UADATA=NAVIGATOR&&NAVIGATOR.userAgentData?NAVIGATOR.userAgentData:undefined;var assignFromEntries=function(arr){for(var i in arr){var propName=arr[i];if(typeof propName==OBJ_TYPE&&propName.length==2){this[propName[0]]=propName[1]}else{this[propName]=undefined}}return this},extend=function(regexes,extensions){var mergedRegexes={};for(var i in regexes){mergedRegexes[i]=extensions[i]&&extensions[i].length%2===0?extensions[i].concat(regexes[i]):regexes[i]}return mergedRegexes},enumerize=function(arr){var enums={};for(var i=0;i0){for(var i in str1){if(lowerize(str1[i])==lowerize(str2))return true}return false}return typeof str1===STR_TYPE?lowerize(str2).indexOf(lowerize(str1))!==-1:false},isExtensions=function(obj){for(var prop in obj){return/^(browser|cpu|device|engine|os)$/.test(prop)}},itemListToArray=function(header){if(!header)return undefined;var arr=[];var tokens=strip(/\\?\"/g,header).split(", ");for(var i=0;i0){if(q.length===2){if(typeof q[1]==FUNC_TYPE){this[q[0]]=q[1].call(this,match)}else{this[q[0]]=q[1]}}else if(q.length===3){if(typeof q[1]===FUNC_TYPE&&!(q[1].exec&&q[1].test)){this[q[0]]=match?q[1].call(this,match,q[2]):undefined}else{this[q[0]]=match?match.replace(q[1],q[2]):undefined}}else if(q.length===4){this[q[0]]=match?q[3].call(this,match.replace(q[1],q[2])):undefined}}else{this[q]=match?match:undefined}}}}i+=2}},strMapper=function(str,map){for(var i in map){if(typeof map[i]===OBJ_TYPE&&map[i].length>0){for(var j=0;j2){this.set(MODEL,"iPad").set(TYPE,TABLET)}break;case UA_OS:if(isSelfNav&&!this.get(NAME)&&NAVIGATOR_UADATA&&NAVIGATOR_UADATA[PLATFORM]){this.set(NAME,NAVIGATOR_UADATA[PLATFORM])}break;case UA_RESULT:var createUAParserItem=function(itemType){return new UAParserItem(itemType,ua,rgxMap[itemType],uaCH).get()};this.set("ua",ua).set(UA_BROWSER,createUAParserItem(UA_BROWSER)).set(UA_CPU,createUAParserItem(UA_CPU)).set(UA_DEVICE,createUAParserItem(UA_DEVICE)).set(UA_ENGINE,createUAParserItem(UA_ENGINE)).set(UA_OS,createUAParserItem(UA_OS)).get()}return this}UAParserItem.prototype.get=function(prop){if(!prop)return this.data;return this.data.hasOwnProperty(prop)?this.data[prop]:undefined};UAParserItem.prototype.parse=function(){if(this.itemType!=UA_RESULT){rgxMapper.call(this.data,this.ua,this.rgxMap)}return this};UAParserItem.prototype.parseCH=function(){var ua=this.ua,uaCH=this.uaCH,rgxMap=this.rgxMap;switch(this.itemType){case UA_BROWSER:var brands=uaCH[FULLVERLIST]||uaCH[BRANDS];if(brands){for(var i in brands){var brandName=brands[i].brand,brandVersion=brands[i].version;if(!/not.a.brand/i.test(brandName)||/chromi/i.test(this.get(NAME))){this.set(NAME,strip(GOOGLE+" ",brandName)).set(VERSION,brandVersion).set(MAJOR,majorize(brandVersion))}}}break;case UA_CPU:var archName=uaCH[ARCHITECTURE];if(archName){if(archName&&uaCH[BITNESS]=="64")archName+="64";rgxMapper.call(this.data,archName+";",rgxMap)}break;case UA_DEVICE:if(uaCH[MOBILE]){this.set(TYPE,MOBILE)}if(uaCH[MODEL]){this.set(MODEL,uaCH[MODEL])}break;case UA_OS:var osName=uaCH[PLATFORM];if(osName){var osVersion=uaCH[PLATFORMVER];if(osName==WINDOWS)osVersion=parseInt(majorize(osVersion),10)>=13?"11":"10";this.set(NAME,osName).set(VERSION,osVersion)}break;case UA_RESULT:var createUAParserItemWithCH=function(itemType){return new UAParserItem(itemType,ua,rgxMap[itemType],uaCH).parseCH().get()};this.set("ua",ua).set(UA_BROWSER,createUAParserItemWithCH(UA_BROWSER)).set(UA_CPU,createUAParserItemWithCH(UA_CPU)).set(UA_DEVICE,createUAParserItemWithCH(UA_DEVICE)).set(UA_ENGINE,createUAParserItemWithCH(UA_ENGINE)).set(UA_OS,createUAParserItemWithCH(UA_OS))}return this};UAParserItem.prototype.set=function(prop,val){this.data[prop]=val;return this};function UAParser(ua,extensions,headers){if(typeof ua===OBJ_TYPE){if(isExtensions(ua)){if(typeof extensions===OBJ_TYPE){headers=extensions}extensions=ua}else{headers=ua;extensions=undefined}ua=undefined}else if(typeof ua===STR_TYPE&&!isExtensions(extensions)){headers=extensions;extensions=undefined}if(!(this instanceof UAParser)){return new UAParser(ua,extensions,headers).getResult()}var userAgent=ua||(NAVIGATOR&&NAVIGATOR.userAgent?NAVIGATOR.userAgent:headers&&headers[USER_AGENT]?headers[USER_AGENT]:EMPTY),HTTP_UACH=new UAParserDataCH(headers,true),regexMap=extensions?extend(defaultRegexes,extensions):defaultRegexes,createUAParserItemFunc=function(itemType){return function(){return new UAParserItem(itemType,userAgent,itemType==UA_RESULT?regexMap:regexMap[itemType],HTTP_UACH).get()}};assignFromEntries.call(this,[["getBrowser",createUAParserItemFunc(UA_BROWSER)],["getCPU",createUAParserItemFunc(UA_CPU)],["getDevice",createUAParserItemFunc(UA_DEVICE)],["getEngine",createUAParserItemFunc(UA_ENGINE)],["getOS",createUAParserItemFunc(UA_OS)],["getResult",createUAParserItemFunc(UA_RESULT)],["getUA",function(){return userAgent}],["setUA",function(ua){userAgent=typeof ua===STR_TYPE&&ua.length>UA_MAX_LENGTH?trim(ua,UA_MAX_LENGTH):ua;return this}]]).setUA(userAgent);return this}UAParser.VERSION=LIBVERSION;UAParser.BROWSER=enumerize([NAME,VERSION,MAJOR]);UAParser.CPU=enumerize([ARCHITECTURE]);UAParser.DEVICE=enumerize([MODEL,VENDOR,TYPE,CONSOLE,MOBILE,SMARTTV,TABLET,WEARABLE,EMBEDDED]);UAParser.ENGINE=UAParser.OS=enumerize([NAME,VERSION]);if(typeof exports!==UNDEF_TYPE){if(typeof module!==UNDEF_TYPE&&module.exports){exports=module.exports=UAParser}exports.UAParser=UAParser}else{if(typeof define===FUNC_TYPE&&define.amd){define(function(){return UAParser})}else if(typeof window!==UNDEF_TYPE){window.UAParser=UAParser}}var $=typeof window!==UNDEF_TYPE&&(window.jQuery||window.Zepto);if($&&!$.ua){var parser=new UAParser;$.ua=parser.getResult();$.ua.get=function(){return parser.getUA()};$.ua.set=function(ua){parser.setUA(ua);var result=parser.getResult();for(var prop in result){$.ua[prop]=result[prop]}}}})(typeof window==="object"?window:this); \ No newline at end of file diff --git a/dist/ua-parser.pack.js b/dist/ua-parser.pack.js index c5d1e9c43..ca1bc8f58 100644 --- a/dist/ua-parser.pack.js +++ b/dist/ua-parser.pack.js @@ -1,4 +1,4 @@ /* UAParser.js v2.0.0-alpha.1 Copyright © 2012-2023 Faisal Salman MIT License */ -!function(i,u){"use strict";function e(i){for(var e={},t=0;tS?yi(i,S):i,this}]]).setUA(o),this}Ni.prototype.get=function(i){return i?this.data.hasOwnProperty(i)?this.data[i]:u:this.data},Ni.prototype.parse=function(){return this.itemType!=L&&w.call(this.data,this.ua,this.rgxMap),this},Ni.prototype.parseCH=function(){var e=this.ua,t=this.uaCH,o=this.rgxMap;switch(this.itemType){case V:var i=t[C]||t[q];if(i)for(var r in i){var a=i[r].brand,r=i[r].version;/not.a.brand/i.test(a)&&!/chromi/i.test(this.get(m))||this.set(m,xi(K+" ",a)).set(v,r).set(h,vi(r))}break;case B:var s=t[x];s&&(s&&"64"==t[A]&&(s+="64"),w.call(this.data,s+";",o));break;case F:t[k]&&this.set(g,k),t[f]&&this.set(f,t[f]);break;case D:s=t[N];s&&(n=t[z],s==ui&&(n=13<=parseInt(vi(n),10)?"11":"10"),this.set(m,s).set(v,n));break;case L:var n=function(i){return new Ni(i,e,o[i],t).parseCH().get()};this.set("ua",e).set(V,n(V)).set(B,n(B)).set(F,n(F)).set($,n($)).set(D,n(D))}return this},Ni.prototype.set=function(i,e){return this.data[i]=e,this},zi.VERSION="2.0.0-alpha.1",zi.BROWSER=e([m,v,h]),zi.CPU=e([x]),zi.DEVICE=e([f,o,g,r,k,n,a,y,_]),zi.ENGINE=zi.OS=e([m,v]),typeof exports!==d?(typeof module!==d&&module.exports&&(exports=module.exports=zi),exports.UAParser=zi):typeof define===c&&define.amd?define(function(){return zi}):typeof i!==d&&(i.UAParser=zi);var Ai,Oi=typeof i!==d&&(i.jQuery||i.Zepto);Oi&&!Oi.ua&&(Ai=new zi,Oi.ua=Ai.getResult(),Oi.ua.get=function(){return Ai.getUA()},Oi.ua.set=function(i){Ai.setUA(i);var e,t=Ai.getResult();for(e in t)Oi.ua[e]=t[e]})}("object"==typeof window?window:this); \ No newline at end of file +!function(i,u){"use strict";function e(i){for(var e={},t=0;tS?yi(i,S):i,this}]]).setUA(o),this}Ni.prototype.get=function(i){return i?this.data.hasOwnProperty(i)?this.data[i]:u:this.data},Ni.prototype.parse=function(){return this.itemType!=L&&w.call(this.data,this.ua,this.rgxMap),this},Ni.prototype.parseCH=function(){var e=this.ua,t=this.uaCH,o=this.rgxMap;switch(this.itemType){case V:var i=t[C]||t[q];if(i)for(var r in i){var a=i[r].brand,r=i[r].version;/not.a.brand/i.test(a)&&!/chromi/i.test(this.get(m))||this.set(m,xi(K+" ",a)).set(v,r).set(h,vi(r))}break;case B:var s=t[x];s&&(s&&"64"==t[A]&&(s+="64"),w.call(this.data,s+";",o));break;case F:t[k]&&this.set(g,k),t[f]&&this.set(f,t[f]);break;case D:s=t[N];s&&(n=t[z],s==ui&&(n=13<=parseInt(vi(n),10)?"11":"10"),this.set(m,s).set(v,n));break;case L:var n=function(i){return new Ni(i,e,o[i],t).parseCH().get()};this.set("ua",e).set(V,n(V)).set(B,n(B)).set(F,n(F)).set($,n($)).set(D,n(D))}return this},Ni.prototype.set=function(i,e){return this.data[i]=e,this},zi.VERSION="2.0.0-alpha.1",zi.BROWSER=e([m,v,h]),zi.CPU=e([x]),zi.DEVICE=e([f,o,g,r,k,a,n,y,_]),zi.ENGINE=zi.OS=e([m,v]),typeof exports!==d?(typeof module!==d&&module.exports&&(exports=module.exports=zi),exports.UAParser=zi):typeof define===c&&define.amd?define(function(){return zi}):typeof i!==d&&(i.UAParser=zi);var Ai,Oi=typeof i!==d&&(i.jQuery||i.Zepto);Oi&&!Oi.ua&&(Ai=new zi,Oi.ua=Ai.getResult(),Oi.ua.get=function(){return Ai.getUA()},Oi.ua.set=function(i){Ai.setUA(i);var e,t=Ai.getResult();for(e in t)Oi.ua[e]=t[e]})}("object"==typeof window?window:this); \ No newline at end of file diff --git a/readme.md b/readme.md index ad229f322..fe1ec957b 100644 --- a/readme.md +++ b/readme.md @@ -477,7 +477,7 @@ http.createServer(function (req, res) { res.setHeader('Accept-CH', getHighEntropyValues); res.setHeader('Critical-CH', getHighEntropyValues); - var ua = uap(req.headers); + var ua = uap(req.headers).withClientHints(); // END since@2.0 */ diff --git a/src/ua-parser.js b/src/ua-parser.js index 6a82ed1ad..51cb0fa3c 100755 --- a/src/ua-parser.js +++ b/src/ua-parser.js @@ -932,26 +932,27 @@ ['data', createUAParserData(itemType, ua, rgxMap, uaCH)] ]); this.parse(); + var isSelfNav = NAVIGATOR && NAVIGATOR.userAgent == ua; switch(this.itemType) { case UA_BROWSER: // Brave-specific detection - if (NAVIGATOR && NAVIGATOR.userAgent == ua && NAVIGATOR.brave && typeof NAVIGATOR.brave.isBrave == FUNC_TYPE) { + if (isSelfNav && NAVIGATOR.brave && typeof NAVIGATOR.brave.isBrave == FUNC_TYPE) { this.set(NAME, 'Brave'); } this.set(MAJOR, majorize(this.get(VERSION))); break; case UA_DEVICE: - if (!this.get(TYPE) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[MOBILE]) { + if (isSelfNav && !this.get(TYPE) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[MOBILE]) { this.set(TYPE, MOBILE); } // iPadOS-specific detection: identified as Mac, but has some iOS-only properties - if (this.get(MODEL) == 'Macintosh' && NAVIGATOR && typeof NAVIGATOR.standalone !== UNDEF_TYPE && NAVIGATOR.maxTouchPoints && NAVIGATOR.maxTouchPoints > 2) { + if (isSelfNav && this.get(MODEL) == 'Macintosh' && NAVIGATOR && typeof NAVIGATOR.standalone !== UNDEF_TYPE && NAVIGATOR.maxTouchPoints && NAVIGATOR.maxTouchPoints > 2) { this.set(MODEL, 'iPad') .set(TYPE, TABLET); } break; case UA_OS: - if (!this.get(NAME) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[PLATFORM] && NAVIGATOR_UADATA[PLATFORM] != 'Unknown') { + if (isSelfNav && !this.get(NAME) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[PLATFORM]) { this.set(NAME, NAVIGATOR_UADATA[PLATFORM]); } break; diff --git a/src/ua-parser.mjs b/src/ua-parser.mjs index e0d93d0d8..4d5df1b29 100644 --- a/src/ua-parser.mjs +++ b/src/ua-parser.mjs @@ -936,26 +936,27 @@ const window = undefined; ['data', createUAParserData(itemType, ua, rgxMap, uaCH)] ]); this.parse(); + var isSelfNav = NAVIGATOR && NAVIGATOR.userAgent == ua; switch(this.itemType) { case UA_BROWSER: // Brave-specific detection - if (NAVIGATOR && NAVIGATOR.userAgent == ua && NAVIGATOR.brave && typeof NAVIGATOR.brave.isBrave == FUNC_TYPE) { + if (isSelfNav && NAVIGATOR.brave && typeof NAVIGATOR.brave.isBrave == FUNC_TYPE) { this.set(NAME, 'Brave'); } this.set(MAJOR, majorize(this.get(VERSION))); break; case UA_DEVICE: - if (!this.get(TYPE) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[MOBILE]) { + if (isSelfNav && !this.get(TYPE) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[MOBILE]) { this.set(TYPE, MOBILE); } // iPadOS-specific detection: identified as Mac, but has some iOS-only properties - if (this.get(MODEL) == 'Macintosh' && NAVIGATOR && typeof NAVIGATOR.standalone !== UNDEF_TYPE && NAVIGATOR.maxTouchPoints && NAVIGATOR.maxTouchPoints > 2) { + if (isSelfNav && this.get(MODEL) == 'Macintosh' && NAVIGATOR && typeof NAVIGATOR.standalone !== UNDEF_TYPE && NAVIGATOR.maxTouchPoints && NAVIGATOR.maxTouchPoints > 2) { this.set(MODEL, 'iPad') .set(TYPE, TABLET); } break; case UA_OS: - if (!this.get(NAME) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[PLATFORM] && NAVIGATOR_UADATA[PLATFORM] != 'Unknown') { + if (isSelfNav && !this.get(NAME) && NAVIGATOR_UADATA && NAVIGATOR_UADATA[PLATFORM]) { this.set(NAME, NAVIGATOR_UADATA[PLATFORM]); } break;