Description
Is your feature request related to a problem? Please describe.
I understand we cannot detect iPad devices, Brave browser, or some additional information with the library running on Node, as it relies on feature detection.
Describe the solution you'd like
I would like to be able to inject the relevant information into ua-parser-js when it's running in Node by sending it from my frontend. It could be either something pretty manual where we could mock/override the navigator/window object, or it could be a companion library that would add the feature check data in headers of requests.
Example:
return fetch('/example', {
headers: {
'x-ua-data': UAParserCompanion.getExtraUADataInBase64()
}
})
console.log(UAParserCompanion.getExtraUADataInBase64());
/*
eyJ3aW5kb3ciOnsibmF2aWdhdG9yIjp7ImJyYXZlIjp7ImlzQnJhdmUiOnRydWV9fSwic3RhbmRhbG9uZSI6dHJ1ZSwibWF4VG91Y2hQb2ludCI6NSwidXNlckFnZW50RGF0YSI6eyJicmFuZHMiOlt7ImJyYW5kIjoiQ2hyb21pdW0iLCJ2ZXJzaW9uIjoiMTM0In0seyJicmFuZCI6Ik5vdDpBLUJyYW5kIiwidmVyc2lvbiI6IjI0In0seyJicmFuZCI6Ikdvb2dsZSBDaHJvbWUiLCJ2ZXJzaW9uIjoiMTM0In1dLCJtb2JpbGUiOmZhbHNlLCJwbGF0Zm9ybSI6Im1hY09TIn19fQ==
// Base64 version of the following:
{
"window": {
"navigator": {
"brave": {
"isBrave": true
}
},
"standalone": true,
"maxTouchPoint": 5,
"userAgentData": {
"brands": [
{
"brand": "Chromium",
"version": "134"
},
{
"brand": "Not:A-Brand",
"version": "24"
},
{
"brand": "Google Chrome",
"version": "134"
}
],
"mobile": false,
"platform": "macOS"
}
}
}
// Note: This configuration doesn't make sense, of course.
*/
Describe alternatives you've considered
My example may not be ideal. I am copying parts of the navigator object, and keeping the shape, but some future feature detection may rely on function calls, which wouldn't serialize. Maybe a flatter structure that doesn't aim to match 1-1 with the existing navigator object could be wiser?
Now, the idea of the companion library is just a thought, but support for providing additional information and allow some kind of feature detection on the backend would be enough.
Additional context
You could tell me to run ua-parser-js directly on the frontend and forward all information to my backend by the same method; and of course it would work. I'm just trying to keep my frontend as small as possible.