From 4e1d1bf3de1527054c7644c8b6ba75f94ba7e2af Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 14:41:35 +0200 Subject: [PATCH 1/3] parseUA - use full client version --- src/utils/device/parseUserAgent.ts | 2 +- test/utils/device/parseUserAgent-test.ts | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/utils/device/parseUserAgent.ts b/src/utils/device/parseUserAgent.ts index 9d9d71e6f7f..5ddc813179b 100644 --- a/src/utils/device/parseUserAgent.ts +++ b/src/utils/device/parseUserAgent.ts @@ -99,7 +99,7 @@ export const parseUserAgent = (userAgent?: string): ExtendedDeviceInformation => const deviceOperatingSystem = concatenateNameAndVersion(operatingSystem.name, operatingSystem.version); const deviceModel = concatenateNameAndVersion(device.vendor, device.model); - const client = concatenateNameAndVersion(browser.name, browser.major || browser.version); + const client = concatenateNameAndVersion(browser.name, browser.version); const { customDeviceModel, customDeviceOS } = checkForCustomValues(userAgent); const deviceType = getDeviceType(userAgent, device, browser, operatingSystem); diff --git a/test/utils/device/parseUserAgent-test.ts b/test/utils/device/parseUserAgent-test.ts index 9171a2a7555..7db47ac83c4 100644 --- a/test/utils/device/parseUserAgent-test.ts +++ b/test/utils/device/parseUserAgent-test.ts @@ -70,8 +70,8 @@ const DESKTOP_UA = [ "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) ElementNightly/2022091301 Chrome/104.0.5112.102 Electron/20.1.1 Safari/537.36", ]; const DESKTOP_EXPECTED_RESULT = [ - makeDeviceExtendedInfo(DeviceType.Desktop, undefined, "Mac OS 10.15.7", "Electron", "20"), - makeDeviceExtendedInfo(DeviceType.Desktop, undefined, "Windows 10", "Electron", "20"), + makeDeviceExtendedInfo(DeviceType.Desktop, undefined, "Mac OS 10.15.7", "Electron", "20.1.1"), + makeDeviceExtendedInfo(DeviceType.Desktop, undefined, "Windows 10", "Electron", "20.1.1"), ]; const WEB_UA = [ @@ -88,16 +88,16 @@ const WEB_UA = [ ]; const WEB_EXPECTED_RESULT = [ - makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS 10.15.7", "Chrome", "104"), - makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows 10", "Chrome", "104"), - makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS 10.10", "Firefox", "39"), - makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS 10.10.2", "Safari", "8"), - makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows Vista", "Firefox", "40"), - makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows 10", "Edge", "12"), + makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS 10.15.7", "Chrome", "104.0.5112.102"), + makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows 10", "Chrome", "104.0.5112.102"), + makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS 10.10", "Firefox", "39.0"), + makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS 10.10.2", "Safari", "8.0.3"), + makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows Vista", "Firefox", "40.0"), + makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows 10", "Edge", "12.246"), // using mobile browser - makeDeviceExtendedInfo(DeviceType.Web, "Apple iPad", "iOS 8.4.1", "Mobile Safari", "8"), - makeDeviceExtendedInfo(DeviceType.Web, "Apple iPhone", "iOS 8.4.1", "Mobile Safari", "8"), - makeDeviceExtendedInfo(DeviceType.Web, "Samsung SM-G973U", "Android 9", "Chrome", "69"), + makeDeviceExtendedInfo(DeviceType.Web, "Apple iPad", "iOS 8.4.1", "Mobile Safari", "8.0"), + makeDeviceExtendedInfo(DeviceType.Web, "Apple iPhone", "iOS 8.4.1", "Mobile Safari", "8.0"), + makeDeviceExtendedInfo(DeviceType.Web, "Samsung SM-G973U", "Android 9", "Chrome", "69.0.3497.100"), ]; From 3b9e3d94713e6346e3fe315d000d6a9fe44cce81 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 14:47:56 +0200 Subject: [PATCH 2/3] dont check for custom element model and os when device type is unknown --- src/utils/device/parseUserAgent.ts | 16 ++++++++++------ test/utils/device/parseUserAgent-test.ts | 3 +++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/utils/device/parseUserAgent.ts b/src/utils/device/parseUserAgent.ts index 5ddc813179b..3c4d76e5db7 100644 --- a/src/utils/device/parseUserAgent.ts +++ b/src/utils/device/parseUserAgent.ts @@ -58,15 +58,16 @@ const getDeviceType = ( return DeviceType.Unknown; }; +interface CustomValues { + customDeviceModel?: string; + customDeviceOS?: string; +} /** * Some mobile model and OS strings are not recognised * by the UA parsing library * check they exist by hand */ -const checkForCustomValues = (userAgent: string): { - customDeviceModel?: string; - customDeviceOS?: string; -} => { +const checkForCustomValues = (userAgent: string): CustomValues => { if (userAgent.includes(BROWSER_KEYWORD)) { return {}; } @@ -97,12 +98,15 @@ export const parseUserAgent = (userAgent?: string): ExtendedDeviceInformation => const device = parser.getDevice(); const operatingSystem = parser.getOS(); + const deviceType = getDeviceType(userAgent, device, browser, operatingSystem); const deviceOperatingSystem = concatenateNameAndVersion(operatingSystem.name, operatingSystem.version); const deviceModel = concatenateNameAndVersion(device.vendor, device.model); const client = concatenateNameAndVersion(browser.name, browser.version); - const { customDeviceModel, customDeviceOS } = checkForCustomValues(userAgent); - const deviceType = getDeviceType(userAgent, device, browser, operatingSystem); + // only try to parse custom model and OS when device type is known + const { customDeviceModel, customDeviceOS } = deviceType !== DeviceType.Unknown + ? checkForCustomValues(userAgent) + : {} as CustomValues; return { deviceType, diff --git a/test/utils/device/parseUserAgent-test.ts b/test/utils/device/parseUserAgent-test.ts index 7db47ac83c4..3fccf0803e1 100644 --- a/test/utils/device/parseUserAgent-test.ts +++ b/test/utils/device/parseUserAgent-test.ts @@ -106,6 +106,8 @@ const MISC_UA = [ "Curl Client/1.0", "banana", "", + // fluffy chat ios + "Dart/2.18 (dart:io)", ]; const MISC_EXPECTED_RESULT = [ @@ -113,6 +115,7 @@ const MISC_EXPECTED_RESULT = [ makeDeviceExtendedInfo(DeviceType.Unknown, undefined, undefined, undefined, undefined), makeDeviceExtendedInfo(DeviceType.Unknown, undefined, undefined, undefined, undefined), makeDeviceExtendedInfo(DeviceType.Unknown, undefined, undefined, undefined, undefined), + makeDeviceExtendedInfo(DeviceType.Unknown, undefined, undefined, undefined, undefined), ]; /* eslint-disable max-len */ From 31af97309535468d219c7f8cb2b533ea442261d3 Mon Sep 17 00:00:00 2001 From: Kerry Archibald Date: Mon, 10 Oct 2022 16:36:36 +0200 Subject: [PATCH 3/3] ignore OS version in browser based sessions --- src/utils/device/parseUserAgent.ts | 9 ++++++++- test/utils/device/parseUserAgent-test.ts | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/utils/device/parseUserAgent.ts b/src/utils/device/parseUserAgent.ts index 3c4d76e5db7..3eee6177652 100644 --- a/src/utils/device/parseUserAgent.ts +++ b/src/utils/device/parseUserAgent.ts @@ -99,7 +99,14 @@ export const parseUserAgent = (userAgent?: string): ExtendedDeviceInformation => const operatingSystem = parser.getOS(); const deviceType = getDeviceType(userAgent, device, browser, operatingSystem); - const deviceOperatingSystem = concatenateNameAndVersion(operatingSystem.name, operatingSystem.version); + + // OSX versions are frozen at 10.15.17 in UA strings https://chromestatus.com/feature/5452592194781184 + // ignore OS version in browser based sessions + const shouldIgnoreOSVersion = deviceType === DeviceType.Web || deviceType === DeviceType.Desktop; + const deviceOperatingSystem = concatenateNameAndVersion( + operatingSystem.name, + shouldIgnoreOSVersion ? undefined : operatingSystem.version, + ); const deviceModel = concatenateNameAndVersion(device.vendor, device.model); const client = concatenateNameAndVersion(browser.name, browser.version); diff --git a/test/utils/device/parseUserAgent-test.ts b/test/utils/device/parseUserAgent-test.ts index 3fccf0803e1..e4ae89d2e0e 100644 --- a/test/utils/device/parseUserAgent-test.ts +++ b/test/utils/device/parseUserAgent-test.ts @@ -70,8 +70,8 @@ const DESKTOP_UA = [ "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) ElementNightly/2022091301 Chrome/104.0.5112.102 Electron/20.1.1 Safari/537.36", ]; const DESKTOP_EXPECTED_RESULT = [ - makeDeviceExtendedInfo(DeviceType.Desktop, undefined, "Mac OS 10.15.7", "Electron", "20.1.1"), - makeDeviceExtendedInfo(DeviceType.Desktop, undefined, "Windows 10", "Electron", "20.1.1"), + makeDeviceExtendedInfo(DeviceType.Desktop, undefined, "Mac OS", "Electron", "20.1.1"), + makeDeviceExtendedInfo(DeviceType.Desktop, undefined, "Windows", "Electron", "20.1.1"), ]; const WEB_UA = [ @@ -88,16 +88,16 @@ const WEB_UA = [ ]; const WEB_EXPECTED_RESULT = [ - makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS 10.15.7", "Chrome", "104.0.5112.102"), - makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows 10", "Chrome", "104.0.5112.102"), - makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS 10.10", "Firefox", "39.0"), - makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS 10.10.2", "Safari", "8.0.3"), - makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows Vista", "Firefox", "40.0"), - makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows 10", "Edge", "12.246"), + makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS", "Chrome", "104.0.5112.102"), + makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows", "Chrome", "104.0.5112.102"), + makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS", "Firefox", "39.0"), + makeDeviceExtendedInfo(DeviceType.Web, undefined, "Mac OS", "Safari", "8.0.3"), + makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows", "Firefox", "40.0"), + makeDeviceExtendedInfo(DeviceType.Web, undefined, "Windows", "Edge", "12.246"), // using mobile browser - makeDeviceExtendedInfo(DeviceType.Web, "Apple iPad", "iOS 8.4.1", "Mobile Safari", "8.0"), - makeDeviceExtendedInfo(DeviceType.Web, "Apple iPhone", "iOS 8.4.1", "Mobile Safari", "8.0"), - makeDeviceExtendedInfo(DeviceType.Web, "Samsung SM-G973U", "Android 9", "Chrome", "69.0.3497.100"), + makeDeviceExtendedInfo(DeviceType.Web, "Apple iPad", "iOS", "Mobile Safari", "8.0"), + makeDeviceExtendedInfo(DeviceType.Web, "Apple iPhone", "iOS", "Mobile Safari", "8.0"), + makeDeviceExtendedInfo(DeviceType.Web, "Samsung SM-G973U", "Android", "Chrome", "69.0.3497.100"), ];