All Projects → GoogleChromeLabs → uach-retrofill

GoogleChromeLabs / uach-retrofill

Licence: Apache-2.0 license
This snippet illustrates how to reconstruct the legacy navigator.userAgent string value from the modern navigator.userAgentData values.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to uach-retrofill

Agent orange
Parse and process User Agents like a secret one
Stars: ✭ 127 (+388.46%)
Mutual labels:  user-agent
User agent
Generator of User-Agent header
Stars: ✭ 227 (+773.08%)
Mutual labels:  user-agent
robots-parser
NodeJS robots.txt parser with support for wildcard (*) matching.
Stars: ✭ 117 (+350%)
Mutual labels:  user-agent
React Useragent
Integrate user-agent detection in an idiomatic React way
Stars: ✭ 154 (+492.31%)
Mutual labels:  user-agent
Mojo
✨ Mojolicious - Perl real-time web framework
Stars: ✭ 2,298 (+8738.46%)
Mutual labels:  user-agent
List Of User Agents
List of major web + mobile browser user agent strings. +1 Bonus script to scrape :)
Stars: ✭ 247 (+850%)
Mutual labels:  user-agent
Fetch Plus
🐕 Fetch+ is a convenient Fetch API replacement with first-class middleware support.
Stars: ✭ 116 (+346.15%)
Mutual labels:  user-agent
php-useragent
A User-agent analyze project which written by PHP.
Stars: ✭ 83 (+219.23%)
Mutual labels:  user-agent
Random User Agent
😎 Google chrome browser extension
Stars: ✭ 201 (+673.08%)
Mutual labels:  user-agent
crawlerdetect
Golang module to detect bots and crawlers via the user agent
Stars: ✭ 22 (-15.38%)
Mutual labels:  user-agent
Device Detector
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
Stars: ✭ 2,106 (+8000%)
Mutual labels:  user-agent
Device Detector Js
A precise user agent parser and device detector written in TypeScript
Stars: ✭ 193 (+642.31%)
Mutual labels:  user-agent
cloudflare-block-bad-bot-ruleset
🚦 Block malicious crawlers with Cloudflare Firewall Rules
Stars: ✭ 178 (+584.62%)
Mutual labels:  user-agent
Devicedetector.net
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
Stars: ✭ 144 (+453.85%)
Mutual labels:  user-agent
Vytal
Browser extension to spoof timezone, geolocation, locale and user agent.
Stars: ✭ 1,449 (+5473.08%)
Mutual labels:  user-agent
Parser Php
Browser sniffing gone too far — A useragent parser library for PHP
Stars: ✭ 1,626 (+6153.85%)
Mutual labels:  user-agent
Ng Device Detector
Angular module to detect OS / Browser / Device
Stars: ✭ 243 (+834.62%)
Mutual labels:  user-agent
user-agent
User-Agent parser for Clojure
Stars: ✭ 24 (-7.69%)
Mutual labels:  user-agent
browserslist-generator
A library that makes generating and validating Browserslists a breeze!
Stars: ✭ 77 (+196.15%)
Mutual labels:  user-agent
useragent-generator
Easily generate correct user-agent strings for popular browsers
Stars: ✭ 62 (+138.46%)
Mutual labels:  user-agent

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].