faisalman / ua-parser-js

"Unmask Your Traffic" - UAParser.js: The Essential Web Development Tool for User-Agent Detection
https://uaparser.dev/
GNU Affero General Public License v3.0
9.28k stars 1.2k forks source link

2.0b2 - withClientHints() returns a promise, when headers are provided #705

Open devenbj opened 9 months ago

devenbj commented 9 months ago

Library version v2.0.0-b2

Describe the bug Following the example: https://docs.uaparser.js.org/v2/api/ua-parser-js/idata/with-client-hints.html for server-side. The example returns a promise with the current client data when the .withClient.Hints() function is added. This generates console errors from the sample code.

To Reproduce Create a page with the v2.0.0b2 version of ua-parser-js. Copy and paste the demo code. Browser errors immediately on the .withClientHints() console.log statements.

Expected behavior An object with the parsed results. This works as expected when not using .withClientHints.

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context It is clear the withClientHints piece is functioning, as my browser changes from Chrome to Brave. For my code, I am feeding in an array of 7 different browsers configs (including Mac OS and iOS), and they all come back as Linux / Brave (my dev platform). They only return when I nest the console.log inside a .then response. When I drop the .withClientHints(), the function returns the data as expected (Brave is identified as Chrome).

castarco commented 9 months ago

I also think that it does not make much sense to return a promise when the result can be computed in a complete synchronous way (as the data is already provided).

The stated return type could be easily conditioned to the passed parameters to fix that interface problem.

Note: I'd contribute a fix if it wasn't because I already paid for the privative license, my work would report benefits only to the lib owner, and I'm not happy with how our doubts are not being resolved.