Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@marufme/device-key

maruf-me658MIT1.1.0TypeScript support: included

A lightweight, modular TypeScript library for comprehensive device detection, fingerprinting, and information gathering in browsers. Features tree-shakeable modules for OS detection, browser analysis, network info, device fingerprinting, and more.

device-inspector, device-analyzer, device-checker, device-insight, device-identify, device-fingerprint, browser-detection, os-detection, device-info, user-agent, device-identification, client-detection, hardware-detection, network-detection, typescript, tree-shakeable, modular, lightweight, browser-api, device-profiling, client-side, web-detection

readme

@marufme/device-key 🔑

A lightweight, comprehensive device detection and fingerprinting library for modern web applications. Get detailed information about user devices, browsers, operating systems, and generate unique device fingerprints.

npm version License: MIT

✨ Features

  • 🖥️ Device Detection: Identify device type (Desktop, Mobile, Tablet)
  • 🌐 Browser Information: Get browser name, version, engine, and vendor
  • 💻 OS Detection: Detect operating system name, version, platform, and architecture
  • 🔋 Battery Status: Monitor battery level, charging status, and charging time
  • 🌍 Network Info: Get network connection type, effectiveType, downlink, RTT, and CPU cores
  • 🆔 Device Fingerprinting: Generate unique, stable device identifiers
  • 🎨 Canvas & WebGL Fingerprinting: Canvas and WebGL helpers used for fingerprints
  • 🔍 IP Detection & VPN Bypass: Detect public/real IP, VPN/Proxy, and possible DNS leaks
  • 🌍 Localization: Language preferences, timezone, DST, and optional coordinates
  • 📱 Hardware Details: Screen resolution, pixel ratio, and CPU cores
  • 🕵️ Incognito Detection: Heuristic detection using StorageManager quota
  • 🔒 Privacy Aware: Server-side safe with graceful fallbacks

🚀 Installation

npm install @marufme/device-key
yarn add @marufme/device-key
pnpm add @marufme/device-key

📖 Quick Start

Basic Usage

import getDeviceInfo from "@marufme/device-key";

// Get comprehensive device information
const deviceInfo = await getDeviceInfo();
console.log(deviceInfo);

Modular Usage

import {
  getOSInfo,
  getBrowserInfo,
  getNetworkInfo,
  getDeviceInfoBasic,
  getDeviceId,
  getBatteryInfo,
  getUserAgent,
  parseUserAgent,
  getLocationInfo,
  getTimezoneInfo,
  getLanguageInfo,
  getIPInfo,
  generateFingerprint,
  getCanvasFingerprint,
  getWebGLFingerprint,
  detectIncognitoMode,
} from "@marufme/device-key";

// Get specific information
const osInfo = getOSInfo();
const browserInfo = getBrowserInfo();
const networkInfo = getNetworkInfo();
const basicDevice = await getDeviceInfoBasic();
const { deviceId } = await getDeviceId();
const battery = await getBatteryInfo();
const ua = getUserAgent();
const uaParsed = parseUserAgent();
const location = await getLocationInfo();
const tz = getTimezoneInfo();
const lang = getLanguageInfo();
const ipInfo = await getIPInfo();
const fingerprint = await generateFingerprint();
const canvasFp = getCanvasFingerprint();
const webglFp = getWebGLFingerprint();
const isIncognito = await detectIncognitoMode();

🔧 API Reference

Main Function

getDeviceInfo(): Promise<Device>

Returns comprehensive device information including OS, browser, device details, network info, user-agent, location, and incognito status.

const deviceInfo = await getDeviceInfo();
// Returns:
// {
//   os: { name, version, platform, architecture },
//   browser: { name, version, engine, vendor },
//   device: {
//     deviceId,
//     deviceType,
//     hardwareConcurrency,
//     screen: { width, height, pixelRatio },
//     battery: { level, charging, chargingTime }
//   },
//   network: { connectionType?, effectiveType?, downlink?, rtt?, cores? },
//   location: {
//     timezone: { timezone, offset, dst },
//     language: { current, types, primary },
//     coordinates?: GeolocationCoordinates,
//     ipInfo?: {
//       publicIP,
//       realIP?,
//       isVPN,
//       isProxy,
//       isTor,
//       country?,
//       city?,
//       isp?,
//       confidence
//     }
//   },
//   userAgent: string,
//   incognito: boolean
// }

OS

getOSInfo(): OSInfo

Detects operating system information.

const osInfo = getOSInfo();
// { name, version, platform, architecture }
// Example: { name: "Windows", version: "10", platform: "Win32", architecture: "64-bit" }

Browser

getBrowserInfo(): BrowserInfo

Detects browser information.

const browserInfo = getBrowserInfo();
// { name, version, engine, vendor }
// Example: { name: "Chrome", version: "120.0.0.0", engine: "Blink", vendor: "Google Inc." }

detectIncognitoMode(): Promise<boolean>

Heuristic detection using StorageManager quota (returns true if incognito/private mode likely).

const isIncognito = await detectIncognitoMode();

Device

getDeviceInfoBasic(): Promise<DeviceBasicInfo>

Gets basic device information including screen details and battery status.

const info = await getDeviceInfoBasic();
// {
//   deviceId,
//   deviceType: "Desktop" | "Mobile" | "Tablet",
//   hardwareConcurrency,
//   screen: { width, height, pixelRatio },
//   battery: { level, charging, chargingTime }
// }

getDeviceId(): Promise<{ deviceId: string }>

Generates or retrieves a stable device identifier. On first run in the browser, it generates a fingerprint and stores it in localStorage under a small key. On non-browser environments, returns "server-mode".

const { deviceId } = await getDeviceId();

getBatteryInfo(): Promise<BatteryInfo>

Gets battery information (where supported).

const battery = await getBatteryInfo();
// { level: 0-100, charging: boolean, chargingTime: number | null }

Network

getNetworkInfo(): NetworkInfo

Gets network connection information and CPU cores where available.

const net = getNetworkInfo();
// {
//   connectionType?,
//   effectiveType?,
//   downlink?,
//   rtt?,
//   cores?
// }

User Agent

getUserAgent(): { userAgent: string }

Returns the current user agent string.

const { userAgent } = getUserAgent();

parseUserAgent(): UserAgentInfo

Lightweight UA parsing helpers.

const ua = parseUserAgent();
// { userAgent, isMobile, isTablet, isDesktop, isBot }

Location & Locale

getLocationInfo(): Promise<LocationInfo>

Aggregates timezone, language, and optional geolocation coordinates (if permitted) and IP information.

const loc = await getLocationInfo();
// {
//   timezone: { timezone, offset, dst },
//   language: { current, types, primary },
//   coordinates?: GeolocationCoordinates,
//   ipInfo?: IPInfo
// }

getTimezoneInfo(): TimezoneInfo

Gets timezone identifier, UTC offset (minutes east of UTC), and DST flag.

const tz = getTimezoneInfo();
// { timezone, offset, dst }

getLanguageInfo(): LanguageInfo

Gets language preferences.

const lang = getLanguageInfo();
// { current, types, primary }

getIPInfo(): Promise<IPInfo>

Advanced IP detection with VPN/Proxy insights. Uses WebRTC leak checks, public IP services, and heuristic VPN/Proxy signals.

const ip = await getIPInfo();
// {
//   publicIP: string,
//   realIP?: string,
//   isVPN: boolean,
//   isProxy: boolean,
//   isTor: boolean,
//   country?: string,
//   city?: string,
//   isp?: string,
//   confidence: number
// }

Fingerprint

generateFingerprint(): Promise<string>

Creates a unique device fingerprint using basic info + Canvas + WebGL, hashed with SHA-256.

const fp = await generateFingerprint();

getCanvasFingerprint(): string

Generates a canvas-based fingerprint string (data URL).

const canvasFp = getCanvasFingerprint();

getWebGLFingerprint(): string

Generates a WebGL-based fingerprint string (vendor::renderer).

const webglFp = getWebGLFingerprint();

Note: Low-level helpers like hashing and info collection are internal; only the functions listed above are part of the public API.

📱 Device Types

The library automatically detects and categorizes devices:

  • Desktop: Traditional computers and laptops
  • Mobile: Smartphones and mobile devices
  • Tablet: Tablet devices (including iPad)

🎯 Use Cases

  • Analytics: Track device types and capabilities
  • User Experience: Adapt UI based on device capabilities
  • Security: Device fingerprinting for fraud detection
  • Performance: Optimize based on device specifications
  • Debugging: Collect device information for troubleshooting
  • A/B Testing: Segment users by device characteristics

🔒 Privacy & Security

  • No External APIs: All detection is done client-side (IP detection may call public IP services)
  • Graceful Fallbacks: Works even when certain APIs are unavailable
  • Server-Side Safe: Can run in Node.js environments; returns conservative defaults
  • User Consent: Geolocation requests are optional and permission-based

🌐 Browser Support

  • Modern Browsers: Chrome 60+, Firefox 55+, Safari 12+, Edge 79+
  • Mobile Browsers: iOS Safari, Chrome Mobile, Samsung Internet
  • Progressive Enhancement: Features gracefully degrade on older browsers

📦 Bundle Size

  • Minified: ~15KB
  • Gzipped: ~5KB
  • Tree-shakeable: Import only what you need

🛠️ Development

# Clone the repository
git clone https://github.com/maruf-me/device-key.git

# Install dependencies
pnpm install

# Start development server
pnpm dev

# Build the package
pnpm build

# Preview build
pnpm preview

📄 License

MIT License - see LICENSE file for details.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📞 Support

🔄 Changelog

See CHANGELOG.md for a list of changes and version history.


Made with ❤️ by MD Maruf Hossain

changelog

1.1.0

Refactor

🎯 Key Changes Summary

Architecture Refactoring

  • Before: Flat utils/ directory with mixed concerns
  • After: Modular modules/ structure with domain-specific organization
  • Impact: Better maintainability, tree-shaking support, and extensibility

New Features Added

  • IP Detection & VPN Bypass: Advanced IP detection with WebRTC leaks
  • Enhanced Location Module: Timezone, language, and geolocation support
  • Improved Browser Detection: Incognito mode detection
  • Better Network Information: Enhanced connection details

Package Configuration Improvements

  • Enhanced metadata and documentation
  • Comprehensive development scripts
  • Optimized keywords for better discoverability
  • Better exports configuration for tree-shaking

📁 File Structure Changes

New Modular Structure

src/
├── modules/                    # 🆕 Organized by domain
│   ├── os/                    # Operating System detection
│   │   ├── detector.ts
│   │   ├── types.ts
│   │   └── index.ts
│   ├── browser/               # Browser detection & capabilities
│   │   ├── detector.ts
│   │   ├── types.ts
│   │   └── index.ts
│   ├── device/                # Device hardware & battery
│   │   ├── detector.ts
│   │   ├── battery.ts
│   │   ├── getDeviceId.ts
│   │   ├── types.ts
│   │   └── index.ts
│   ├── network/               # Network information
│   │   ├── detector.ts
│   │   ├── types.ts
│   │   └── index.ts
│   ├── fingerprint/           # Device fingerprinting
│   │   ├── generator.ts
│   │   ├── types.ts
│   │   └── index.ts
│   ├── user-agent/            # User agent parsing
│   │   ├── detector.ts
│   │   ├── types.ts
│   │   └── index.ts
│   └── location/              # 🆕 Location & IP detection
│       ├── detector.ts
│       ├── types.ts
│       ├── index.ts
│       └── README.md
├── core/                      # Main device info aggregator
├── types/                     # Centralized type exports
└── index.ts                   # Clean public API

Removed Files

  • src/utils/ directory (all files moved to modules)
  • src/types/device-info.ts (consolidated into src/types/index.ts)

🆕 New Features

1. IP Detection & VPN Bypass Module

import { getIPInfo } from "@marufme/device-key";

const ipInfo = await getIPInfo();
console.log(ipInfo);
/*
{
  publicIP: "203.0.113.1",      // VPN IP
  realIP: "192.168.1.100",      // Real IP (if detected)
  isVPN: true,                  // VPN detected
  isProxy: false,               // Proxy detected
  isTor: false,                 // Tor detected
  country: "United States",     // Location
  city: "New York",
  isp: "NordVPN",              // VPN provider
  confidence: 0.7              // Detection confidence
}
*/

Detection Methods:

  • WebRTC IP Detection: ~70-80% VPN bypass rate
  • VPN/Proxy Detection: ~85-90% accuracy for major services
  • DNS Leak Detection: ~60-70% detection rate
  • Geolocation Analysis: Country, city, ISP information