Lightweight browser, device & network detection library

npm i aki-info-detect
npm size stars
โš ๏ธ Server Headers Required: For deep hardware detection via Client Hints API, configure: Accept-CH: Sec-CH-UA, Sec-CH-UA-Mobile, Sec-CH-UA-Platform, Sec-CH-UA-Platform-Version, Sec-CH-UA-Arch, Sec-CH-UA-Bitness
๐ŸŒ
Browser
Nameโ€”
Productโ€”
Mobileโ€”
Languageโ€”
๐Ÿ’ป
Operating System
Nameโ€”
Versionโ€”
Platformโ€”
โš™๏ธ
Processor
CPUโ€”
Coresโ€”
Architectureโ€”
๐ŸŽฎ
Memory & Graphics
RAMโ€”
GPUโ€”
Manufacturerโ€”
๐Ÿ”‹
Battery
Levelโ€”
Chargingโ€”
๐Ÿ“ฑ
Display
Resolutionโ€”
Pixel Ratioโ€”
Color Depthโ€”
๐Ÿ“ถ
Connection
Typeโ€”
Downlinkโ€”
RTTโ€”
๐ŸŒ
Network
IPClick fetch
ISPโ€”
Countryโ€”
๐Ÿ“
Location
Latitudeโ€”
Longitudeโ€”
Accuracyโ€”
๐Ÿ“‹ Raw JSON Output
Loading...

Features

๐ŸŒ Browser Detection

Name, version, rendering engine

๐Ÿ’ป OS Detection

Windows, macOS, Linux, iOS, Android

โš™๏ธ Hardware Info

CPU cores, RAM, GPU, Apple Silicon

๐ŸŒ Network Info

Public IP, ISP, country (cached)

๐Ÿ“ฑ Screen Info

Resolution, pixel ratio, orientation

๐Ÿ”‹ Battery Status

Charging state, level percentage

Installation

Package Manager

npm install aki-info-detect
# or
yarn add aki-info-detect
# or
pnpm add aki-info-detect

CDN (ES Module)

<script type="module">
  import akiInfoDetect from 'https://unpkg.com/aki-info-detect/dist/aki-info-detect.js';
  const info = await akiInfoDetect();
  console.log(info);
</script>

CDN (UMD)

<script src="https://unpkg.com/aki-info-detect/dist/aki-info-detect.umd.cjs"></script>
<script>
  akiInfoDetect().then(info => console.log(info));
</script>

Quick Start

import akiInfoDetect from 'aki-info-detect';

// Get all info
const info = await akiInfoDetect();
console.log(info.browser);  // "Chrome 120.0"
console.log(info.os.name);  // "macOS"
console.log(info.CPU);      // "Apple M3 Pro"

// Tree-shakeable imports
import { detectBrowser, detectOS } from 'aki-info-detect';
const browser = detectBrowser();
const os = detectOS();

Server Configuration

For deep hardware detection, configure your server to send Client Hints headers:

Express.js

app.use((req, res, next) => {
  res.setHeader('Accept-CH', 
    'Sec-CH-UA, Sec-CH-UA-Mobile, Sec-CH-UA-Platform, ' +
    'Sec-CH-UA-Platform-Version, Sec-CH-UA-Arch, Sec-CH-UA-Bitness'
  );
  next();
});

Nginx

add_header Accept-CH "Sec-CH-UA, Sec-CH-UA-Mobile, Sec-CH-UA-Platform, Sec-CH-UA-Platform-Version, Sec-CH-UA-Arch, Sec-CH-UA-Bitness";

Vite

// vite.config.js
export default {
  server: {
    headers: {
      'Accept-CH': 'Sec-CH-UA, Sec-CH-UA-Mobile, Sec-CH-UA-Platform, ...'
    }
  }
};

Bundle Size

  • ES Module: 14.85 kB
  • UMD: 9.38 kB
  • Gzipped: ~3.8 kB

Browser Support

All modern browsers with ES2020+ support:

  • Chrome/Edge 90+
  • Firefox 88+
  • Safari 14+
  • Opera 76+

API Reference

Default Export: akiInfoDetect()

Returns a Promise that resolves to an object containing all detected information.

const info = await akiInfoDetect();

Return Object

{
  // Browser info
  browser: string,          // "Chrome 120.0"
  product: string,          // "Gecko"
  manufacturer: string,     // "Google Inc."
  isMobile: boolean,        // true/false
  language: string,         // "en-US"
  
  // OS info
  os: {
    name: string,           // "macOS"
    version: string,        // "14.1.2"
    string: string          // "macOS 14.1.2"
  },
  
  // Hardware
  CPU: string,              // "Apple M3 Pro"
  CPUCore: number,          // 12
  arch: string,             // "arm64"
  RAM: number,              // 16 (GB)
  GPU: string,              // "Apple M3 Pro"
  
  // Battery
  battery: {
    isCharging: boolean,    // true/false
    level: number           // 0-100
  },
  
  // Methods
  getScreen: () => Object,
  getConnection: () => Object,
  getIP: () => Promise<string>,
  getISP: () => Promise<string>,
  getCountry: () => Promise<string>,
  getLocation: () => Promise<Object>
}

Named Exports

detectBrowser()

Returns browser name and version.

import { detectBrowser } from 'aki-info-detect';
const browser = detectBrowser(); // "Chrome 120.0"

detectOS()

Returns OS information.

import { detectOS } from 'aki-info-detect';
const os = detectOS();
// { name: "macOS", version: "14.1.2", string: "macOS 14.1.2" }

getHardwareInfo()

Returns CPU, GPU, RAM information (async).

import { getHardwareInfo } from 'aki-info-detect';
const hw = await getHardwareInfo();
// { CPU: "...", cores: 12, arch: "...", RAM: 16, GPU: "..." }

getNetworkInfo()

Returns network information with caching (async).

import { getNetworkInfo } from 'aki-info-detect';
const net = await getNetworkInfo();
// { ip: "...", isp: "...", country: "..." }

getScreen()

Returns screen dimensions and properties.

import { getScreen } from 'aki-info-detect';
const screen = getScreen();
// { width: 1920, height: 1080, pixelRatio: 2, ... }

getBattery()

Returns battery status (async).

import { getBattery } from 'aki-info-detect';
const battery = await getBattery();
// { isCharging: true, level: 85 }

Caching

Network requests (IP, ISP, Country) are cached for 1 hour to reduce API calls.

// First call: fetches from API
const ip1 = await info.getIP();

// Within 1 hour: returns cached value
const ip2 = await info.getIP();

Error Handling

try {
  const info = await akiInfoDetect();
  console.log(info.browser);
} catch (error) {
  console.error('Detection failed:', error);
}

TypeScript Support

Full TypeScript declarations included.

import akiInfoDetect, { type DetectionResult } from 'aki-info-detect';

const info: DetectionResult = await akiInfoDetect();