Property 'userAgentData' does not exist on type 'Navigator'

Viewed 2591

Since navigator.userAgent's information will be reduced so I want to migrate to User-Agent Client Hints but it shows error like this:

enter image description here

How do I solve this, please help. Many thanks

2 Answers

You need to install types for Navigator.userAgentData

  1. Install user agent types from npm:

    npm i -D user-agent-data-types

  2. In the tsconfig.json add:

{
   "compilerOptions": {
    ...
    "types": [
      "./node_modules/user-agent-data-types"
     ]
   },
}

Now you should be able to see userAgentData property on navigator object.

Related