All Projects → wasabeef → flutter_ua_client_hints

wasabeef / flutter_ua_client_hints

Licence: MIT License
Provide User-Agent Client Hints to a Flutter app.

Programming Languages

dart
5743 projects
swift
15916 projects
kotlin
9241 projects
ruby
36898 projects - #4 most used programming language
Makefile
30231 projects
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to flutter ua client hints

Browser
Useragent analysis tool.浏览器分析判断工具 - 用户代理、操作系统信息
Stars: ✭ 789 (+2822.22%)
Mutual labels:  useragent
Browserslist Useragent
🦔A utility to match a browserslist query with user agent strings
Stars: ✭ 231 (+755.56%)
Mutual labels:  useragent
vue-device-detector
A tiny device detector plugin of Vue for mobile🐔👁
Stars: ✭ 43 (+59.26%)
Mutual labels:  useragent
Browscap Java
A blazingly fast and memory efficient (thread-safe) Java client on top of the BrowsCap CSV source files.
Stars: ✭ 123 (+355.56%)
Mutual labels:  useragent
Uap Ruby
A simple, comprehensive Ruby gem for parsing user agent strings with the help of BrowserScope's UA database
Stars: ✭ 188 (+596.3%)
Mutual labels:  useragent
Fake Useragent
A wide variety of random useragents
Stars: ✭ 253 (+837.04%)
Mutual labels:  useragent
Browser.php
A PHP Class to detect a user's Browser. This encapsulation provides a breakdown of the browser and the version of the browser using the browser's user-agent string. This is not a guaranteed solution but provides an overall accurate way to detect what browser a user is using.
Stars: ✭ 546 (+1922.22%)
Mutual labels:  useragent
uainfer
Infer the user agent from its User Agent string
Stars: ✭ 21 (-22.22%)
Mutual labels:  useragent
Useragentparser
UserAgent parsing done right
Stars: ✭ 225 (+733.33%)
Mutual labels:  useragent
ImNotSpider
浏览器User Agent生成器
Stars: ✭ 17 (-37.04%)
Mutual labels:  useragent
Mobile Device Detect
Detect mobile device and its type.
Stars: ✭ 132 (+388.89%)
Mutual labels:  useragent
Next Useragent
next-useragent parses browser user-agent strings for next.js
Stars: ✭ 158 (+485.19%)
Mutual labels:  useragent
react-useragent
Higher order component to add user agent information to your react components
Stars: ✭ 13 (-51.85%)
Mutual labels:  useragent
React Device Detect
Detect device, and render view according to detected device type.
Stars: ✭ 1,145 (+4140.74%)
Mutual labels:  useragent
browserslist-generator
A library that makes generating and validating Browserslists a breeze!
Stars: ✭ 77 (+185.19%)
Mutual labels:  useragent
User agent
HTTP User Agent parser for the Go programming language.
Stars: ✭ 578 (+2040.74%)
Mutual labels:  useragent
Ng Device Detector
Angular module to detect OS / Browser / Device
Stars: ✭ 243 (+800%)
Mutual labels:  useragent
micell
A collection of functions for front-end development
Stars: ✭ 16 (-40.74%)
Mutual labels:  useragent
ember-useragent
An Ember addon for Fastboot-enabled UserAgent parsing via UAParser.js.
Stars: ✭ 34 (+25.93%)
Mutual labels:  useragent
useragent-generator
Easily generate correct user-agent strings for popular browsers
Stars: ✭ 62 (+129.63%)
Mutual labels:  useragent

User-Agent Client Hints for Flutter

What's User-Agent Client Hints?

User-Agent Client Hints
Improving user privacy and developer experience with User-Agent Client Hints
User-Agent Client Hints Demo on Browser

⬇️ Response Accept-CH ⬆️ Request header ⬆️ RequestExample value Description
UA Sec-CH-UA "Chromium";v="84",
"Google Chrome";v="84"
List of browser brands and their significant version.
UA-Mobile Sec-CH-UA-Mobile ?1 Boolean indicating if the browser is
on a mobile device (?1 for true) or not (?0 for false).
UA-Full-Version Sec-CH-UA-Full-Version "84.0.4143.2" The complete version for the browser.
UA-Platform Sec-CH-UA-Platform "Android" The platform for the device,
usually the operating system (OS).
UA-Platform-Version Sec-CH-UA-Platform-Version "10" The version for the platform or OS.
UA-Arch Sec-CH-UA-Arch "ARM64" The underlying architecture for the device.
While this may not be relevant to displaying the page,
the site may want to offer a download which defaults to the right format.
UA-Model Sec-CH-UA-Model "Pixel 3" The device model.

Installation

  1. This plugin is set the Null Safety.

  2. Add this to your package's pubspec.yaml file

dependencies:
  ua_client_hints: ^1.x.x
  1. You can install packages from the command line
$ flutter pub get

Usage

With Dio

Add to the request header.

class AppDio with DioMixin implements Dio {
  AppDio._([BaseOptions options]) {
    options = BaseOptions(
      baseUrl: 'https://wasabeef.jp',
    );

    this.options = options;
    interceptors.add(InterceptorsWrapper(
      onRequest: (options) async {
        // Add User-Agent Client Hints
        options.headers.addAll(await userAgentClientHintsHeader());
        return options;
      },
    ));
  }

  static Dio getInstance() => AppDio._();
}

APIs

final String ua = await userAgent();

print('User-Agent: $ua');  // e.g.. 'SampleApp/1.0.0 (Android 11; Pixel 4 XL; coral; arm64-v8a)'
final UserAgentData uaData = await userAgentData();

print('platform:        ${uaData.platform}');              // e.g.. 'Android'
print('platformVersion: ${uaData.platformVersion}');       // e.g.. '10'
print('model:           ${uaData.model}');                 // e.g.. 'Pixel 4 XL'
print('architecture:    ${uaData.architecture}');          // e.g.. 'arm64-v8a'
print('brand:           ${uaData.brand}');                 // e.g.. 'google'
print('mobile:          ${uaData.mobile}');                // e.g.. true
print('device:          ${uaData.device}');                // e.g.. 'coral'
print('appName:         ${uaData.package.appName}');       // e.g.. 'SampleApp'
print('appVersion:      ${uaData.package.appVersion}');    // e.g.. '1.0.0'
print('packageName:     ${uaData.package.packageName}');   // e.g.. 'jp.wasabeef.ua'
print('buildNumber:     ${uaData.package.buildNumber}');   // e.g.. '1'
final Map<String, dynamic> header = await userAgentClientHintsHeader();

print("Sec-CH-UA-Arch:             ${header['Sec-CH-UA-Arch']}");             // e.g.. 'arm64-v8a'
print("Sec-CH-UA-Model:            ${header['Sec-CH-UA-Model']}");            // e.g.. 'Pixel 4 XL'
print("Sec-CH-UA-Platform:         ${header['Sec-CH-UA-Platform']}");         // e.g.. 'Android'
print("Sec-CH-UA-Platform-Version: ${header['Sec-CH-UA-Platform-Version']}"); // e.g.. '10'
print("Sec-CH-UA:                  ${header['Sec-CH-UA']}");                  // e.g.. '"SampleApp"; v="1.0.0"'
print("Sec-CH-UA-Full-Version:     ${header['Sec-CH-UA-Full-Version']}");     // e.g.. '1.0.0'
print("Sec-CH-UA-Mobile:           ${header['Sec-CH-UA-Mobile']}");           // e.g.. '?1' (true) or '?0' (false)
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].