Skip to content

Commit ae2c5f5

Browse files
committed
fix: include ua in all DetectedInfo classes
1 parent 0a6ea2d commit ae2c5f5

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ implements DetectedInfo<'node', 'node', NodeJS.Platform, string> {
8484
public readonly type = 'node'
8585
public readonly name: 'node' = 'node' as const
8686
public readonly os: NodeJS.Platform = platform
87+
public readonly ua?: UserAgentDataInfo = undefined
8788
constructor(
8889
public readonly version: string,
8990
) {}
@@ -98,6 +99,7 @@ implements DetectedInfo<RuntimeName, RuntimeName, ProviderInfo/* , string */> {
9899
public readonly runtime: RuntimeInfo | undefined = runtimeInfo
99100
// TODO: include version if possible
100101
public readonly version: null = null
102+
public readonly ua?: UserAgentDataInfo = undefined
101103

102104
constructor(
103105
public readonly name: RuntimeName,
@@ -112,6 +114,7 @@ export class SearchBotDeviceInfo
112114
implements
113115
DetectedInfo<'bot-device', Browser, OperatingSystem | null, string> {
114116
public readonly type = 'bot-device'
117+
public readonly ua?: UserAgentDataInfo = undefined
115118
constructor(
116119
public readonly name: Browser,
117120
public readonly version: string,
@@ -126,9 +129,7 @@ export class BotInfo implements DetectedInfo<'bot', 'bot', null> {
126129
public readonly name: 'bot' = 'bot' as const
127130
public readonly version: null = null
128131
public readonly os: null = null
129-
constructor(
130-
public readonly ua?: UserAgentDataInfo,
131-
) {}
132+
public readonly ua?: UserAgentDataInfo = undefined
132133
}
133134

134135
export class ReactNativeInfo
@@ -137,11 +138,13 @@ implements DetectedInfo<'react-native', 'react-native', null> {
137138
public readonly name: 'react-native' = 'react-native' as const
138139
public readonly version: null = null
139140
public readonly os: null = null
141+
public readonly ua?: UserAgentDataInfo = undefined
140142
}
141143

142144
export class JSDOMInfo
143145
implements DetectedInfo<'jsdom', Browser, OperatingSystem | null, string> {
144146
public readonly type = 'jsdom'
147+
public readonly ua?: UserAgentDataInfo = undefined
145148
constructor(
146149
public readonly name: Browser,
147150
public readonly version: string,
@@ -152,6 +155,7 @@ implements DetectedInfo<'jsdom', Browser, OperatingSystem | null, string> {
152155
export class HappyDomInfo
153156
implements DetectedInfo<'happy-dom', Browser, OperatingSystem | null, string> {
154157
public readonly type = 'happy-dom'
158+
public readonly ua?: UserAgentDataInfo = undefined
155159
constructor(
156160
public readonly name: Browser,
157161
public readonly version: string,

test/server.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { runtime } from 'std-env'
22
import { describe, expect, it, test } from 'vitest'
33
import {
4+
asyncDetect,
45
detect,
56
getNodeVersion,
67
getServerVersion,
@@ -53,7 +54,7 @@ describe('Server Detection', () => {
5354
'Sec-CH-UA-Bitness': '"64"',
5455
'Sec-CH-UA-Mobile': '?1',
5556
'Sec-CH-UA-Model': '"Pixel 2 XL"',
56-
'Sec-CH-UA-Full-Version': '"73.1.2343B.TR"',
57+
'Sec-CH-UA-Platform-Version': '"73.1.2343B.TR"',
5758
'Sec-CH-UA-Platform': '"Windows"',
5859
'Sec-CH-UA-Full-Version-List': '"Microsoft Edge"; v="92.0.902.73", "Chromium"; v="92.0.4515.131", "?Not:Your Browser"; v="3.1.2.0"',
5960
})).toMatchInlineSnapshot(`
@@ -91,11 +92,25 @@ describe('Server Detection', () => {
9192
"mobile": true,
9293
"model": "Pixel 2 XL",
9394
"platform": "Windows",
94-
"platformVersion": "",
95+
"platformVersion": "73.1.2343B.TR",
9596
}
9697
`)
9798
expect(lookupServerUserAgentHints({
9899
'Sec-CH-UA-Mobile': '?0',
99100
})?.mobile).toBe(false)
100101
})
102+
test('Windows 11 server detection', async () => {
103+
const info = await asyncDetect({
104+
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
105+
httpHeaders: {
106+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
107+
'Sec-CH-UA-Platform': '"Windows"',
108+
'Sec-CH-UA-Platform-Version': '13.0.0',
109+
},
110+
})
111+
expect(info).toBeDefined()
112+
expect(info?.type).toBe('browser')
113+
expect(info?.name).toBe('chrome')
114+
expect(info?.os).toBe('Windows 11')
115+
})
101116
})

0 commit comments

Comments
 (0)