npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-user-agent

v1.0.3

Published

Generate random user-agent strings for browsers and operating systems, including Chinese alternatives

Readme

# node-user-agent

一个用于生成随机 User-Agent 字符串的 Node.js 模块,支持主流和国产操作系统及浏览器。

## 安装

```bash
npm install node-user-agent

使用方法

基本用法

const userAgent = require('node-user-agent');

// 生成完全随机的User-Agent(主要方法)
console.log(userAgent.toString());

// 向后兼容:generate方法仍然可用
console.log(userAgent.generate());

// 生成随机系统信息
console.log(userAgent.generateSystemInfo());

指定操作系统

// 只生成Windows系统的User-Agent
console.log(userAgent.toString({ osType: 'windows' }));

// 只生成Android系统的User-Agent
console.log(userAgent.toString({ osType: 'android' }));

// 生成国产操作系统的User-Agent
console.log(userAgent.toString({ osType: 'harmonyos' }));

指定浏览器

// 只生成Chrome浏览器的User-Agent
console.log(userAgent.toString({ browserType: 'chrome' }));

// 只生成Firefox浏览器的User-Agent
console.log(userAgent.toString({ browserType: 'firefox' }));

// 生成国产浏览器的User-Agent
console.log(userAgent.toString({ browserType: 'qqbrowser' }));

获取系统信息

// 获取随机系统信息(不生成User-Agent)
const systemInfo = userAgent.generateSystemInfo();
console.log(`操作系统: ${systemInfo.name}`);
console.log(`版本: ${systemInfo.version}`);
console.log(`类型: ${systemInfo.type}`);

获取支持的操作系统和浏览器列表

// 获取浏览器支持的操作系统列表
console.log(userAgent.getSupportedOS('chrome'));

// 获取操作系统支持的浏览器列表
console.log(userAgent.getSupportedBrowsers('windows'));

解析 User-Agent

// 解析 User-Agent 字符串
const parsedInfo = userAgent.parse('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');
console.log(parsedInfo);
// 输出:
// {
//   browser: { name: 'Chrome', version: '91.0.4472.124', type: 'chrome' },
//   os: { name: 'Windows', version: '10.0', type: 'windows' },
//   device: 'Desktop'
// }

支持的操作系统

主流操作系统

  • Windows (windows)
  • macOS (macos)
  • Linux (linux)
  • Android (android)
  • iOS (ios)

国产操作系统

  • HarmonyOS (harmonyos)
  • 麒麟系统 (kylin)
  • 统信UOS (uos)

支持的浏览器

主流浏览器

  • Chrome (chrome)
  • Firefox (firefox)
  • Safari (safari)
  • Edge (edge)

国产浏览器

  • QQ浏览器 (qqbrowser)
  • UC浏览器 (ucbrowser)
  • 360安全浏览器 (360se)

API 参考

toString([options])

生成随机 User-Agent 字符串(主要方法)

参数

  • options.osType (string): 指定操作系统类型
  • options.browserType (string): 指定浏览器类型

返回值

(string): User-Agent 字符串

generate([options])

toString 方法的别名(向后兼容)

generateSystemInfo([options])

生成随机系统信息对象

参数

  • options.osType (string): 指定操作系统类型

返回值

(Object): 包含操作系统信息的对象

getSupportedOS(browserType)

获取浏览器支持的操作系统列表

参数

  • browserType (string): 浏览器类型

返回值

(Array): 支持的操作系统列表

getSupportedBrowsers(osType)

获取操作系统支持的浏览器列表

参数

  • osType (string): 操作系统类型

返回值

(Array): 支持的浏览器列表

parse(userAgent)

解析 User-Agent 字符串

参数

返回值

(Object): 解析结果,包含浏览器、操作系统和设备信息

许可证

MIT