Closed Bug 1914448 Opened 1 year ago Closed 5 months ago

Implement NavigatorUAData interface

Categories

(Core :: DOM: Core & HTML, enhancement)

Firefox 131
enhancement

Tracking

()

RESOLVED DUPLICATE of bug 1750143

People

(Reporter: dotproto, Unassigned)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:131.0) Gecko/20100101 Firefox/131.0

Steps to reproduce:

As a web and WebExtensions developer, I occasionally need to implement features that reference the current web browser. This includes mentioning the name of the user's browser, providing browser-specific instructions, including screenshots of the current browser UI, and gating features based on the browser's capabilities. For the latter case feature detection can be insufficient due to browsers supporting similar-but-different function signatures or the inability to perform feature detection synchronously.

Given that parsing the userAgent string is strongly discouraged, the next best option for detecting the name and version of the user's browser seems to be the User-Agent Client Hints API (https://wicg.github.io/ua-client-hints/#dom-navigatorua-useragentdata).

Mozilla's position on User Agent Client Hints is currently "neutral" (https://mozilla.github.io/standards-positions/#ua-client-hints). This position is primarily focused on exposing client hints in HTTP headers, but the position statement also includes the following note:

"The proposed NavigatorUAData interface JS API is preferable to use of header fields as it would better allow for auditing of the use of the information."

  1. Open any website.
  2. Open developer tools.
  3. Execute the following snippet: navigator.userAgentData.brands

Actual results:

The following error is logged to the console:

Uncaught TypeError: can't access property "brands", navigator.userAgentData is undefined

Expected results:

The console should log an array of NavigatorUAData objects (https://wicg.github.io/ua-client-hints/#navigatoruadata).

On the relevant WebKit feature request (https://bugs.webkit.org/show_bug.cgi?id=276940) a commenter noted that there's a webcompat-addon intervention (bug 1898952, https://webcompat.com/issues/119767) to mock this object on digits.t-mobile.com.

https://github.com/mozilla-extensions/webcompat-addon/pull/362/files#diff-edfea982a0178b7a37361cb10b82f2fa16a793a3aaddabe651627aea35e8024d

The Bugbug bot thinks this bug should belong to the 'Core::JavaScript Engine' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → JavaScript Engine
Product: Firefox → Core

This is a DOM API. Redirecting to a better component.

Component: JavaScript Engine → DOM: Core & HTML
Status: UNCONFIRMED → RESOLVED
Closed: 5 months ago
Duplicate of bug: 1750143
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.