Back to Content

NavigatorUAData

files/en-us/web/api/navigatoruadata/index.md

latest2.9 KB
Original Source

{{APIRef("User-Agent Client Hints API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The NavigatorUAData interface of the {{domxref("User-Agent Client Hints API", "", "", "nocode")}} returns information about the browser and operating system of a user.

An instance of this object is returned by calling {{domxref("Navigator.userAgentData")}} or {{domxref("WorkerNavigator.userAgentData")}}. Therefore, this interface has no constructor.

[!NOTE] The terms high entropy and low entropy refer to the amount of information these values reveal about the browser. The values returned as properties are deemed low entropy, which are unlikely to identify a user. The {{domxref("NavigatorUAData.getHighEntropyValues()")}} can be used to request additional high entropy values, which could potentially reveal more identifying information. These values are therefore retrieved via a {{jsxref("Promise")}}, allowing time for the browser to request user permission, or make other checks.

Instance properties

  • {{domxref("NavigatorUAData.brands")}} {{ReadOnlyInline}} {{Experimental_Inline}}
    • : Returns an array of brand information containing the browser name and version.
  • {{domxref("NavigatorUAData.mobile")}} {{ReadOnlyInline}} {{Experimental_Inline}}
    • : Returns true if the user-agent is running on a mobile device.
  • {{domxref("NavigatorUAData.platform")}} {{ReadOnlyInline}} {{Experimental_Inline}}
    • : Returns the platform brand the user-agent is running on.

Instance methods

  • {{domxref("NavigatorUAData.getHighEntropyValues()")}} {{Experimental_Inline}}
    • : Returns a {{jsxref("Promise")}} that resolves with a dictionary object containing low entropy information and requested high entropy information about the browser.
  • {{domxref("NavigatorUAData.toJSON()")}} {{Experimental_Inline}}
    • : A serializer that returns a JSON representation of the low entropy properties of the NavigatorUAData object.

Examples

Getting the brands

The following example prints the value of {{domxref("NavigatorUAData.brands")}} to the console.

js
console.log(navigator.userAgentData.brands);

Returning high entropy values

In the following value a number of hints are requested using the {{domxref("NavigatorUAData.getHighEntropyValues()")}} method. When the promise resolves, this information is printed to the console.

js
navigator.userAgentData
  .getHighEntropyValues([
    "architecture",
    "model",
    "platform",
    "platformVersion",
    "fullVersionList",
  ])
  .then((ua) => {
    console.log(ua);
  });

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also