
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
client-parser
Advanced tools
A utility to detect the device type (Android, iOS, Windows Phone, PC, unknown) based on the User Agent string.
The client-parser is a utility to detect detailed device information from the browser's User Agent string.
Blink
, Gecko
, WebKit
, Trident
) and its version.isMobile
, isTablet
) for quick checks.DeviceInfo
interface) for enhanced code safety and developer experience.To install the package, run the following command:
npm install client-parser
or
yarn add client-parser
or
pnpm add client-parser
or
bun add client-parser
const getDeviceType = require('client-parser');
const userAgentString =
'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0.1 Mobile/15E148 Safari/604.1';
const platformString = 'iPhone';
const deviceInfo = getDeviceType(userAgentString, platformString);
// Log some of the detected information
console.log('Device Type:', deviceInfo.type); // Outputs: e.g., "pc", "android", "ios", "unknown"
console.log('Operating System:', deviceInfo.os); // Outputs: e.g., "Windows", "Android", "iOS"
console.log('Browser:', deviceInfo.browser); // Outputs: e.g., "Chrome", "Safari", "Firefox"
console.log('Is Mobile:', deviceInfo.isMobile); // Outputs: true or false
console.log('Is Tablet:', deviceInfo.isTablet); // Outputs: true or false
import getDeviceType from 'client-parser';
const userAgentString =
'Mozilla/5.0 (iPhone; CPU iPhone OS 17_0_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0.1 Mobile/15E148 Safari/604.1';
const platformString = 'iPhone';
const deviceInfo = getDeviceType(userAgentString, platformString);
// Log some of the detected information
console.log('Device Type:', deviceInfo.type); // Outputs: e.g., "pc", "android", "ios", "unknown"
console.log('Operating System:', deviceInfo.os); // Outputs: e.g., "Windows", "Android", "iOS"
console.log('Browser:', deviceInfo.browser); // Outputs: e.g., "Chrome", "Safari", "Firefox"
console.log('Is Mobile:', deviceInfo.isMobile); // Outputs: true or false
console.log('Is Tablet:', deviceInfo.isTablet); // Outputs: true or false
import getDeviceType, { IDeviceInfo } from 'client-parser';
const desktopUserAgent: string =
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
const desktopPlatform: string = 'Win32';
const currentDevice: IDeviceInfo = getDeviceType(
desktopUserAgent,
desktopPlatform
);
// Log some of the detected information
console.log('Device Type:', deviceInfo.type); // Outputs: e.g., "pc", "android", "ios", "unknown"
console.log('Operating System:', deviceInfo.os); // Outputs: e.g., "Windows", "Android", "iOS"
console.log('Browser:', deviceInfo.browser); // Outputs: e.g., "Chrome", "Safari", "Firefox"
console.log('Is Mobile:', deviceInfo.isMobile); // Outputs: true or false
console.log('Is Tablet:', deviceInfo.isTablet); // Outputs: true or false
The getDeviceType() function returns an object conforming to the DeviceInfo interface, providing comprehensive details about the client's environment.
export interface IDeviceInfo {
/** The raw User Agent string used for detection. */
userAgentString: string;
/** Information about the device itself. */
device: {
/** The general category of the device: "android", "ios", "windows_phone", "pc", or "unknown". */
type: 'android' | 'ios' | 'windows_phone' | 'pc' | 'unknown';
/** A more specific name for the device (e.g., "iPhone", "iPad", "Android Phone", "Windows PC"). */
name: string;
/** Placeholder for device model (currently 'unknown'). */
model: string;
/** Placeholder for device manufacturer (currently 'unknown'). */
manufacturer: string;
};
/** Information about the browser's rendering engine. */
engine: {
/** The name of the rendering engine (e.g., "Blink", "Gecko", "WebKit", "Trident"). */
name: string;
/** The version of the rendering engine. */
version: string;
};
/** Information about the operating system. */
os: {
/** The name of the operating system (e.g., "Android", "iOS", "Windows Phone", "Windows", "macOS", "Linux"). */
name: string;
/** The version of the operating system. Undefined if not detectable. */
version?: string;
/** Placeholder for OS architecture (currently undefined). */
architecture?: string;
};
/** Information about the browser. */
browser: {
/** The name of the browser (e.g., "Edge", "Opera", "Firefox", "Chrome", "Safari", "Internet Explorer"). */
name: string;
/** The version of the browser. */
version: string;
};
/** The value of navigator.platform, if provided. */
platform: string;
/** A boolean indicating if the user agent is detected as a bot (currently always false, requires separate logic). */
isBot: boolean;
}
This project is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0).
For more details, please visit the Creative Commons License Page.
Special thanks to the following resources:
User Agent string parsing is generally effective but not 100% foolproof. User Agents can be spoofed, incomplete, or vary across different browser versions and custom builds. For critical applications, consider combining this with feature detection (e.g., checking for specific browser APIs) for more robust results.
No, this library focuses on broader device categories (phone, tablet, PC) and operating systems. Detecting specific device models from the User Agent string alone is often unreliable and not within the scope of this lightweight utility.
You can remove the package by running:
npm uninstall client-parser
or
yarn remove client-parser
or
pnpm remove client-parser
or
bun remove client-parser
M♢NTΛSIM |
FAQs
A utility to detect the device type (Android, iOS, Windows Phone, PC, unknown) based on the User Agent string.
The npm package client-parser receives a total of 5 weekly downloads. As such, client-parser popularity was classified as not popular.
We found that client-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.