ua-parser-js icon indicating copy to clipboard operation
ua-parser-js copied to clipboard

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

Open devenbj opened this issue 1 year ago • 1 comments
trafficstars

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):

  • OS: Ubuntu 23.10
  • Browser: Brave
  • Version: 121

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).

devenbj avatar Feb 02 '24 06:02 devenbj

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.

castarco avatar Feb 06 '24 11:02 castarco