Lightweight browser, device & network detection library

npm i aki-info-detect
npm size stars

Welcome to aki-info-detect

aki-info-detect is a modern, lightweight JavaScript library that provides comprehensive device, browser, and system information detection for web applications. Built with performance and developer experience in mind, it leverages modern browser APIs including the Client Hints API for accurate hardware detection while maintaining a minimal footprint (~3.8 kB gzipped).

Whether you need to customize user experiences based on device capabilities, gather analytics data, or implement platform-specific features, aki-info-detect provides a unified, easy-to-use API that works seamlessly across all modern browsers.

โšก Quick Start: Install with npm install aki-info-detect and start detecting in seconds!

Key Benefits

๐ŸŽฏ Comprehensive Detection

Browser, OS, CPU, GPU, RAM, network, battery, and more from a single library

โšก Performance-First

Minimal bundle size with tree-shakeable exportsโ€”import only what you need

๐Ÿ”ฎ Future-Proof

Built on modern Web APIs with graceful fallbacks for older browsers

๐Ÿ’ช Apple Silicon Ready

Advanced detection for Apple M-series chips (M1, M2, M3, M4, and beyond)

๐Ÿ”’ Privacy-Conscious

Implements caching for network requests to minimize external API calls

๐Ÿ“ฆ Zero Dependencies

No external runtime dependenciesโ€”just pure, optimized JavaScript

Common Use Cases

1. Adaptive User Interfaces

Dynamically adjust your UI based on device capabilities and screen properties:

const info = await akiInfoDetect();
if (info.isMobile) {
  loadMobileUI();
} else if (info.RAM < 4) {
  enableLowMemoryMode();
}

2. Analytics & User Insights

Gather detailed technical data to understand your user base:

const info = await akiInfoDetect();
analytics.track('page_view', {
  browser: info.browser,
  os: info.os.string,
  device: info.isMobile ? 'mobile' : 'desktop',
  gpu: info.GPU
});

3. Feature Detection & Progressive Enhancement

Enable or disable features based on browser capabilities:

const info = await akiInfoDetect();
const chromeVersion = parseInt(info.browser.split(' ')[1]);
if (info.browser.includes('Chrome') && chromeVersion >= 90) {
  enableAdvancedFeatures();
}

4. Platform-Specific Optimization

Optimize content delivery based on hardware capabilities:

const info = await akiInfoDetect();
if (info.CPU === 'Apple Silicon') {
  loadWebPImages();
} else if (info.GPU.includes('NVIDIA')) {
  enableHardwareAcceleration();
}

5. Network-Aware Loading

Adapt content loading strategies based on connection quality:

const info = await akiInfoDetect();
const conn = info.getConnection();
if (conn.type === '4g' && conn.downlink > 5) {
  loadHDContent();
} else {
  loadCompressedContent();
}

Comparison with Similar Libraries

aki-info-detect stands out from other detection libraries with its modern approach and comprehensive feature set:

Feature aki-info-detect Platform.js UA-Parser.js Detect.js
Bundle Size (gzipped) ~3.8 kB ~2.5 kB ~9 kB Varies
Client Hints API โœ… โŒ โŒ โŒ
GPU Detection โœ… โŒ โŒ โŒ
Apple Silicon Detection โœ… (M1-MX) โŒ โŒ โŒ
Network Info (IP/ISP) โœ… โŒ โŒ โŒ
Battery & Geolocation โœ… โŒ โŒ โŒ
Tree-shakeable โœ… โš ๏ธ โš ๏ธ โš ๏ธ
TypeScript Support โœ… Full โš ๏ธ Community โœ… โŒ
Active Maintenance โœ… โš ๏ธ โœ… โŒ Archived

Key Differentiators

  • vs. Platform.js: Modern evolution with Client Hints API support, hardware detection (GPU, RAM), and network capabilities
  • vs. UA-Parser.js: Lighter bundle while providing more comprehensive information including hardware and network detection
  • vs. Detect.js: Active maintenance (Detect.js is archived), smaller focused API, modern Web API integration

Frequently Asked Questions

General Questions

What browsers does aki-info-detect support?

All modern browsers with ES2020+ support: Chrome/Edge 89+, Firefox 88+, Safari 14+, Opera 76+. Client Hints features work best in Chromium-based browsers.

Does it work in Node.js or server-side environments?

No, aki-info-detect is specifically designed for browser environments. It relies on browser APIs like navigator, screen, and Web APIs that are not available in Node.js.

How accurate is the detection?

Very accurate for modern browsers that support Client Hints API. For browsers without Client Hints, it falls back to user agent parsing which is still reliable but less detailed. GPU and CPU detection is most accurate in Chromium-based browsers.

Is user agent string spoofing a concern?

While user agents can be spoofed, Client Hints API provides more reliable detection. For critical functionality, always combine with feature detection rather than relying solely on browser/platform detection.

Privacy & Security

Does aki-info-detect collect or transmit user data?

No. The library only detects information locally in the browser. The optional network info feature (getNetworkInfo()) makes a request to a public IP API, but this is only triggered when you explicitly call that method.

What about user privacy?

aki-info-detect is privacy-conscious. Network requests are cached for 1 hour to minimize external API calls, and all detection happens client-side. No data is sent to our servers.

Is it GDPR compliant?

Detection of browser/device information is generally considered functional data necessary for website operation. However, always review your local regulations and privacy policies, especially when using geolocation or storing detected data.

Technical Questions

Why do I need to configure server headers?

The Client Hints API requires the server to explicitly request detailed information via Accept-CH headers. Without these headers, browsers will only provide basic user agent data. This is a browser security feature designed to enhance user privacy.

Can I use it with React, Vue, or other frameworks?

Absolutely! aki-info-detect is framework-agnostic. Check the Documentation tab for React Hook and Vue Composable examples.

How do I reduce bundle size further?

Use tree-shakeable imports to include only the functions you need:

import { detectBrowser, detectOS } from 'aki-info-detect';

Does it support TypeScript?

Yes, full TypeScript declarations are included in the package.

How often is the network information cached?

Network info (IP, ISP, country) is cached for 1 hour by default. You can force a refresh by passing true to getNetworkInfo(true).

Troubleshooting

Why am I getting generic hardware info?

Make sure your server is configured to send the required Accept-CH headers. Without these headers, detailed Client Hints data won't be available. Check the Documentation tab for server configuration examples.

Why is GPU detection returning "Unknown"?

GPU detection works best in Chromium browsers with Client Hints. Safari and Firefox have limited support. Also, some browsers may restrict this information for privacy reasons.

The library says "Unknown" for many fields. What's wrong?

Check browser console for errors, ensure you're using a supported browser version, and verify that your server is sending proper Client Hints headers (see the Documentation tab for Server Configuration).

๐Ÿš€ Ready to get started? Check out the Demo tab to see the library in action, or visit the Documentation tab for installation instructions and code examples.
โš ๏ธ 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();