Skip to content

This snippet illustrates how to reconstruct the legacy navigator.userAgent string value from the modern navigator.userAgentData values.

License

Notifications You must be signed in to change notification settings

GoogleChromeLabs/uach-retrofill

Repository files navigation

UA-CH retrofill

This snippet illustrates how to reconstruct the legacy navigator.userAgent string value from the modern navigator.userAgentData values. The legacy navigator.userAgent is created only if the current navigator.userAgent string matches the reduced User-Agent specification outlined in User-Agent Reduction.

Usage instructions

Copy the contents of uach-retrofill.js to the relevant location in your project.

Import the function from the module:

import { overrideUserAgentUsingClientHints } from './uach-retrofill.js';

The overrideUserAgentUsingClientHints() function takes an array of hints that will be used to generate the legacy user-agent string format and update the value in navigator.userAgent.

The various hints used, which you can optionally pass in based on your needs are:

  • architecture - the CPU architecture
  • bitness - the Operating System's underlying CPU architecture bitness (e.g., "32" or "64")
  • model - the model on Android
  • platformVersion - the Operating System's version
  • uaFullVersion - the browser's full version, in case the significant version (provided by default) is not enough
  • wow64 - whether or not the browser is running in 32-bit mode on 64-bit Windows

For example, if you need the full uaFullVersion, you would specify:

overrideUserAgentUsingClientHints(["uaFullVersion"]).then(() => {
  // navigator.userAgent will be updated with the generated string
  document.getElementById("output").innerHTML = navigator.userAgent;
})

Demo

https://googlechromelabs.github.io/uach-retrofill/demo.html

Contributing

Please see the Code of Conduct and Contributing guides.

About

This snippet illustrates how to reconstruct the legacy navigator.userAgent string value from the modern navigator.userAgentData values.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •