refactor: switch to bowser for user agent parsing (#30)

This commit is contained in:
hampus-fluxer
2026-01-05 14:32:55 +01:00
committed by GitHub
parent a9da71c7d7
commit 2cd7aa5863
8 changed files with 396 additions and 326 deletions

View File

@@ -59,6 +59,7 @@
"@radix-ui/react-switch": "^1.2.6",
"@sentry/react": "10.32.1",
"@simplewebauthn/browser": "13.2.2",
"bowser": "2.13.1",
"clsx": "2.1.1",
"colorjs.io": "0.6.0",
"combokeys": "3.0.1",
@@ -97,7 +98,6 @@
"react-zoom-pan-pinch": "3.7.0",
"rxjs": "7.8.2",
"thumbhash": "0.1.1",
"ua-parser-js": "2.0.7",
"undici": "7.16.0",
"unique-names-generator": "4.7.1",
"update-electron-app": "3.1.2",

View File

@@ -73,6 +73,9 @@ importers:
'@simplewebauthn/browser':
specifier: 13.2.2
version: 13.2.2
bowser:
specifier: 2.13.1
version: 2.13.1
clsx:
specifier: 2.1.1
version: 2.1.1
@@ -187,9 +190,6 @@ importers:
thumbhash:
specifier: 0.1.1
version: 0.1.1
ua-parser-js:
specifier: 2.0.7
version: 2.0.7
undici:
specifier: 7.16.0
version: 7.16.0
@@ -3737,6 +3737,9 @@ packages:
resolution: {integrity: sha512-d0II/GO9uf9lfUHH2BQsjxzRJZBdsjgsBiW4BvhWk/3qoKwQFjIDVN19PfX8F2D/r9PCMTtLWjYVCFrpeYUzsw==}
deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
bowser@2.13.1:
resolution: {integrity: sha512-OHawaAbjwx6rqICCKgSG0SAnT05bzd7ppyKLVUITZpANBaaMFBAsaNkto3LoQ31tyFP5kNujE8Cdx85G9VzOkw==}
brace-expansion@1.1.12:
resolution: {integrity: sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==}
@@ -4159,9 +4162,6 @@ packages:
resolution: {integrity: sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==}
engines: {node: '>= 0.8', npm: 1.2.8000 || >= 1.4.16}
detect-europe-js@0.1.2:
resolution: {integrity: sha512-lgdERlL3u0aUdHocoouzT10d9I89VVhk0qNRmll7mXdGfJT1/wqZ2ZLA4oJAjeACPY5fT1wsbq2AT+GkuInsow==}
detect-libc@2.1.2:
resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==}
engines: {node: '>=8'}
@@ -4892,9 +4892,6 @@ packages:
is-potential-custom-element-name@1.0.1:
resolution: {integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==}
is-standalone-pwa@0.1.1:
resolution: {integrity: sha512-9Cbovsa52vNQCjdXOzeQq5CnCbAcRk05aU62K20WO372NrTv0NxibLFCK6lQ4/iZEFdEA3p3t2VNOn8AJ53F5g==}
is-there@4.5.2:
resolution: {integrity: sha512-ixMkfz3rtS1vEsLf0TjgjqUn96Q0ukpUVDMnPYVocJyTzu2G/QgEtqYddcHZawHO+R31cKVPggJmBLrm1vJCOg==}
@@ -6609,13 +6606,6 @@ packages:
engines: {node: '>=14.17'}
hasBin: true
ua-is-frozen@0.1.2:
resolution: {integrity: sha512-RwKDW2p3iyWn4UbaxpP2+VxwqXh0jpvdxsYpZ5j/MLLiQOfbsV5shpgQiw93+KMYQPcteeMQ289MaAFzs3G9pw==}
ua-parser-js@2.0.7:
resolution: {integrity: sha512-CFdHVHr+6YfbktNZegH3qbYvYgC7nRNEUm2tk7nSFXSODUu4tDBpaFpP1jdXBUOKKwapVlWRfTtS8bCPzsQ47w==}
hasBin: true
uiohook-napi@1.5.4:
resolution: {integrity: sha512-7vPVDNwgb6MwTgviA/dnF2MrW0X5xm76fAqaOAC3cEKkswqAZOPw1USu14Sr6383s5qhXegcJaR63CpJOPCNAg==}
engines: {node: '>= 16'}
@@ -11098,6 +11088,8 @@ snapshots:
boolean@3.2.0:
optional: true
bowser@2.13.1: {}
brace-expansion@1.1.12:
dependencies:
balanced-match: 1.0.2
@@ -11543,8 +11535,6 @@ snapshots:
destroy@1.2.0: {}
detect-europe-js@0.1.2: {}
detect-libc@2.1.2: {}
detect-node@2.1.0: {}
@@ -12432,8 +12422,6 @@ snapshots:
is-potential-custom-element-name@1.0.1: {}
is-standalone-pwa@0.1.1: {}
is-there@4.5.2: {}
is-unicode-supported@0.1.0: {}
@@ -14339,14 +14327,6 @@ snapshots:
typescript@5.9.3: {}
ua-is-frozen@0.1.2: {}
ua-parser-js@2.0.7:
dependencies:
detect-europe-js: 0.1.2
is-standalone-pwa: 0.1.1
ua-is-frozen: 0.1.2
uiohook-napi@1.5.4:
dependencies:
node-gyp-build: 4.8.4

View File

@@ -344,7 +344,7 @@ export default () => {
reuseExistingChunk: true,
},
utils: {
test: /[\\/]node_modules[\\/](lodash|clsx|qrcode|thumbhash|ua-parser-js|match-sorter)[\\/]/,
test: /[\\/]node_modules[\\/](lodash|clsx|qrcode|thumbhash|bowser|match-sorter)[\\/]/,
name: 'utils',
priority: 28,
reuseExistingChunk: true,

View File

@@ -17,7 +17,7 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {UAParser} from 'ua-parser-js';
import Bowser from 'bowser';
import Config from '~/Config';
import {getElectronAPI, isDesktop} from '~/utils/NativeUtils';
@@ -39,14 +39,16 @@ let cachedClientInfo: ClientInfo | null = null;
let preloadPromise: Promise<ClientInfo> | null = null;
const parseUserAgent = (): ClientInfo => {
const parser = new UAParser();
const hasNavigator = typeof navigator !== 'undefined';
const userAgent = hasNavigator ? navigator.userAgent : '';
const parser = Bowser.getParser(userAgent);
const result = parser.getResult();
return {
browserName: normalize(result.browser.name),
browserVersion: normalize(result.browser.version),
osName: normalize(result.os.name),
osVersion: normalize(result.os.version),
arch: normalize(result.cpu.architecture),
arch: normalize(hasNavigator ? navigator.platform : undefined),
};
};