Skip to content

Conversation

dotneet
Copy link
Collaborator

@dotneet dotneet commented Apr 2, 2022

  • No breaking changes.
  • Override results from user-agent by client hints result only if enabled client hints feature.

@DamianGlowala DamianGlowala changed the title feat: Support Client Hints feat: support client hints Apr 12, 2024
@memic84
Copy link

memic84 commented Jun 18, 2025

Any plans on getting this merged?

@@ -135,7 +135,30 @@ export default function ({ $device }) {
}
```

`clientHints.enabled` enables client hints feature.(default by false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`clientHints.enabled` enables client hints feature.(default by false)
`clientHints.enabled` enables client hints feature (false by default).

😄


## User-Agent Client Hints Support

To enable Client Hints, set clientHints.enabled options to true.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
To enable Client Hints, set clientHints.enabled options to true.
To enable Client Hints, set `clientHints.enabled` options to `true`.

Comment on lines +172 to +179
function deleteUndefinedProperties(obj) {
for (const key of Object.keys(obj)) {
if (typeof obj[key] === 'undefined') {
delete obj[key]
}
}
return obj
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function deleteUndefinedProperties(obj) {
for (const key of Object.keys(obj)) {
if (typeof obj[key] === 'undefined') {
delete obj[key]
}
}
return obj
}
function deleteUndefinedProperties(obj) {
return Object.fromEntries(
Object.entries(obj).filter(([_, value]) => typeof value !== 'undefined')
)
}

💅

Comment on lines +159 to +169
const ios = undefined
const android = undefined
const windows = platform === 'Windows'
const macOS = platform === 'macOS'
const isSafari = undefined
const isFirefox = undefined
const isEdge = hasBrand('Microsoft Edge')
const isChrome = hasBrand('Google Chrome')
const isSamsung = undefined
const isCrawler = undefined
return deleteUndefinedProperties({ mobile, mobileOrTablet, ios, android, windows, macOS, isSafari, isFirefox, isEdge, isChrome, isSamsung, isCrawler })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why setting these to undefined if we're deleting them right away ?

Comment on lines +144 to +148
const brands = uaHeader.split(',').map(b => b.trim()).map(brandStr => {
const parsed = brandStr.match(REGEX_CLIENT_HINT_BRAND)
console.log(brandStr, parsed)
return {brand: parsed[1], version: parsed[2]}
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const brands = uaHeader.split(',').map(b => b.trim()).map(brandStr => {
const parsed = brandStr.match(REGEX_CLIENT_HINT_BRAND)
console.log(brandStr, parsed)
return {brand: parsed[1], version: parsed[2]}
})
const brands = uaHeader.split(',').map(brandStr => {
const [,brand,version] = brandStr.trim().match(REGEX_CLIENT_HINT_BRAND)
return { brand, version }
})
  • Removed console.log()
  • Removed map() dedicated to trimming
  • Destructured parsed array

this part isn't defensive enough imo

Comment on lines +150 to +160
results from `navigator.userAgent` are overridden.

### Server Side

the following request headers are referred to detect a device and a platform.

- sec-ch-ua
- sec-ch-mobile
- sec-ch-platform

results from user-agent header are overridden.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
results from `navigator.userAgent` are overridden.
### Server Side
the following request headers are referred to detect a device and a platform.
- sec-ch-ua
- sec-ch-mobile
- sec-ch-platform
results from user-agent header are overridden.
Results from `navigator.userAgent` are overridden.
### Server Side
The following request headers are referred to detect a device and a platform.
- `sec-ch-ua`
- `sec-ch-mobile`
- `sec-ch-platform`
Results from user-agent header are overridden.

const macOS = platform === 'macOS'
const isSafari = undefined
const isFirefox = undefined
const isEdge = hasBrand('Microsoft Edge')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these brands' list would benefit from being stored in a kind of enum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants